Our Products:   CompleteFTP  edtFTPnet/Free  edtFTPnet/PRO  edtFTPj/Free  edtFTPj/PRO
0 votes
2.1k views
in Java FTP by (120 points)
recategorized by

We need to rename the file after the SFTP transfer.  The transfer itself runs successfully. But renaming fails.

Actually all the commands we tried fail: 

We tried the following commands:

'rename f1 f2'

'ls'

'cd <dir>'.

We use: com.enterprisedt.net.ftp.SecureFileTransferClient

The log :

==============================

17:07:56,417 PROTOCOL: SFTP
17:07:56,418 REMOTE_PORT: 22
17:07:56,418 setServerValidationStatus
17:07:56,418 SERVER VALIDATION ENABLED: false
17:07:56,418 setConnectMode
17:07:56,418 CONNECT_MODE:Passive
17:07:56,418 Connecting to server ....
17:07:57,595 Connected to server !
17:07:57,595 setTransferType
17:07:57,595 TRANSFER_TYPE:Binary
17:07:57,595 Local File: /local/home/file1
17:07:57,595 Remote File: /file2
17:07:59,097 Remote size == Local size (499)
17:07:59,097 
17:07:59,098 Execute Command: rename f2  f2.test
17:07:59,405 Failed to execute command 'rename f2  f2.test'
com.enterprisedt.net.ftp.FTPException: Failed to execute command 'rename f2  f2.test'
    at com.enterprisedt.net.ftp.ssh.SCPClient.executeCommand(SCPClient.java:1030)
    at com.enterprisedt.net.ftp.async.internal.ExecuteCommandTask.run(ExecuteCommandTask.java:89)
    at com.enterprisedt.net.ftp.async.internal.FTPTaskProcessor$b.run(FTPTaskProcessor.java:590)
Exception in thread "main" UploadException: MultiFTPUploadProcessor: Exception: 
    at MultiFTPUploadProcessor.process(MultiFTPUploadProcessor.java:129)
    at MultiFTPUploadProcessor.main(MultiFTPUploadProcessor.java:1024)
17:07:59,925 Processed systems: [5306]
Caused by: UploadException: com.enterprisedt.net.ftp.FTPException: Failed to execute command 'rename f2  f2.test'
    at MultiFTPUploadProcessor.sendOther(MultiFTPUploadProcessor.java:467)
    at MultiFTPUploadProcessor.send(MultiFTPUploadProcessor.java:313)
    at MultiFTPUploadProcessor.process(MultiFTPUploadProcessor.java:96)
    ... 1 more
Caused by: com.enterprisedt.net.ftp.FTPException: Failed to execute command 'rename f2  f2.test'
    at com.enterprisedt.net.ftp.ssh.SCPClient.executeCommand(SCPClient.java:1030)
    at com.enterprisedt.net.ftp.async.internal.ExecuteCommandTask.run(ExecuteCommandTask.java:89)
    at com.enterprisedt.net.ftp.async.internal.FTPTaskProcessor$b.run(FTPTaskProcessor.java:590)

===============================

The connection is done like this:

SecureFileTransferClient connectOther()

{

       SecureFileTransferClient ftpClient = new SecureFileTransferClient();
        
       ftpClient.setRemoteHost(host);
        
       ftpClient.setUserName(user);
     
       ftpClient.setPassword(psw);
        
        setProtocol(ftpClient,'sftp');
        
      
        setServerValidationStatus(false);
        
         //CONNECT MODE
        setConnectMode(Passive);
        
        //CONNECT !!!
        log.info("Connecting to server " + ftpClient.getRemoteHost());
        ftpClient.connect();
        log.info("Connected to server " + ftpClient.getRemoteHost());
        
        //TRANSFER TYPE
        setTransferType(BINARY);
        
        return ftpClient;

}

Thank you for your help in advance.

Greg.

 

1 Answer

0 votes
by (2.7k points)

You can't generally execute commands like that, but have you tried the RenameFile method?

by (120 points)
Thank you very much for the quick response.
Yes  Rename File method works! Thank you for the advice.
But we have a generic class which handles all the ftp requests.
So this class is supposed to be able to implement basic commands available for the protocol (ex.  sftp,ftps,ftp). A particular transfer can have several commands to implement.
All those commands come from configuration.
So, we thought we can use:
   SecureFileTransferClient ftpClient = new SecureFileTransferClient();
   .......
   ftpClient.executeCommand(<ANY COMMAND>);

It looks like it's not the case.
Could you please tell me what is the purpose of ftpClient.executeCommand(command) method?

Thank you very much!
Greg.
by (161k points)
executeCommand is used for special commands supported by the server (known as SITE commands). It can't be used for renaming or deleting or the usual operations.

Categories

...