Our Products:   CompleteFTP  edtFTPnet/Free  edtFTPnet/PRO  edtFTPj/Free  edtFTPj/PRO
0 votes
5.9k views
in Java FTP by (560 points)
Using EDTPro..

After I sftp files to my openSSH server, I cannot move or delete those files. I'm using Windows OS and I'm getting the error message:

Access is denied: Make sure the disk is not full or write-protected and that the file is not currently in use.

Is the outputstream for the file closed inside the put() method?

8 Answers

0 votes
by (162k points)
Yes, for put(String,String) it certainly is. Which method are you using?

Is the outputstream for the file closed inside the put() method?
0 votes
by (560 points)
I'm using:

com.enterprisedt.net.ftp.ssh.SSHFTPClient

put(java.lang.String localPath, java.lang.String remoteFile)
Put a local file onto the FTP server


I tried moving the files in FileZilla and I was able to move/delete the files I sftp'd.

The source files are okay to move and delete, its the destination (remote) files that I can't get rid of or move.
0 votes
by (162k points)
Can you please email us the log file to support at enterprisedt dot com? Set it to DEBUG level.
0 votes
by (560 points)
I'm working on getting this log file together for you but I think I found something that can help without it. I nailed down when the problem happens:

If you just transfer a file to another location, the problem does NOT exist.
However, if you create a directory, ftp.mkdir(String), then transfer a file to that newly created directory, ftp.put(String, String), then the problem pops up -- if you try to delete or move the file, Windows complains because the file is in use.

I was able to duplicate this test 100% of the times. Here is the sample code below. Let me know if you still need me to send the logs:
public class testing 
{
   public static void main(String[] args) 
   {
      String sLocalFile = "C:\\image.jpg";

      // In this example, the path "/cygdrive/d/Me" Exists....  newfolder is the new directory
      String sRemoteFile = "/cygdrive/d/Me/newfolder/image.jpg";
      String sRemoteFoldername = "/cygdrive/d/Me/newfolder";

      String sServer = "localhost";
      String sUserName = "ausername";
      String sPassword = "apassword";
      SSHFTPClient ftp = new SSHFTPClient();
      
      try
      {      
         // set remote host
         ftp.setRemoteHost( sServer);
   
         System.out.println( " Setting user-name and password");      
         ftp.setAuthentication( sUserName, sPassword);
   
         System.out.println( " Turning off server validation");      
         ftp.getValidator().setHostValidationEnabled( false);
   
         // connect to the server
         System.out.println( " Connecting to server");      
         ftp.connect();               
         System.out.println( " Connected");
         
         ftp.mkdir( sRemoteFoldername);
         System.out.println( "Created Folder: " + sRemoteFoldername);
         
         ftp.put( sLocalFile, sRemoteFile);
         System.out.println( "Put file: " + sLocalFile + " to " + sRemoteFile);
         ftp.quit();
      }
      catch(FTPException ex)
      {         
         System.out.println( "FTPError Connecting. " + ex.getMessage());
      }
      catch(IOException ex)
      {
         System.out.println( "IOError Connecting. " + ex.getMessage());         
      }
      
   }
}


By the way, the new directory you create is not in use, just all of the files or subdirectories you create under it are....
0 votes
by (51.6k points)
Hi Ron

FYI, I've managed to repeat this problem on my machine, which will make it much easier to fix it. I'll let you know as soon as I've got some news.

Thanks once again
Hans
0 votes
by (51.6k points)
Hi again Ron

OK, I worked out a problem. It's not a bug. It's due to the permissions that edtFTPj/PRO chooses for newly created directories.

By default the UMask is 0022, which means that the file that's created will not have group and world write permissions. If you start up the cygwin console and do an 'ls -l' on the directory you've created, you'll see that the permissions are 'drwxr-xr-x+' (or 0755). This comes about because the permissions are set using the expression '0777 & ~0022=0755'. You should find that if you log into cygwin using the same user that you're SFTP'ing with then you will be able to delete the file and the directory. The reason why you can't do from Windows Explorer is that you're a different user and other users are not allowed to write to or delete the file.

To change this, you'll either need to change the umask using SSHFTPClient.setUmask("0000") or by using the SSHFTPClient.changeMode(int,string) method.

I hope that helps.

- Hans
0 votes
by (560 points)
You were right... Since my default Windows account didn't have a password, I had to create a new user with a password to do SFTP (Since a password is a requirement on the user who you are trying to login as)

I tried it and it worked. I set the Umask to "0000" and through windows, under a different user name, I'm able to modify/delete the files.

Thanks again for all your help.
0 votes
by (162k points)
Just FYI, a umask of 000 isn't a safe one to use except for testing.

You were right... Since my default Windows account didn't have a password, I had to create a new user with a password to do SFTP (Since a password is a requirement on the user who you are trying to login as)

I tried it and it worked. I set the Umask to "0000" and through windows, under a different user name, I'm able to modify/delete the files.

Thanks again for all your help.

Categories

...