Post a reply

Options
Add an Attachment

If you do not want to add an Attachment to your Post, please leave the Fields blank.

(maximum 10 MB; please compress large files; only common media, archive, text and programming file formats are allowed)

Options

Topic review

Lino

Thanks a lot Martin, looking forward to it.
Lino

Renaming Files on FTP

Hello,

i'm having a problem trying to rename FTP files. My basic use case is to download the files and then move them from one FTP folder to another "archive" folder.

Following sample code works and does successfully rename the file, because it's wrapped with try/catch. The first ExecuteCommand call is throwing Exception and that's what's bothering me, i can't figure out what i'm doing wrong.

string moveCmd = "RNFR /source/testx.zip";


try
{
   session.ExecuteCommand(moveCmd); // always produces an exception.
}
catch (Exception ex)
{
   Log.Error("ExceptionLog, RNFR", ex);
}

moveCmd = "RNTO /source/testy.zip";
session.ExecuteCommand(moveCmd); // no exception here


This is the exception being thrown:
WinSCP.SessionRemoteException: File exists, ready for destination name.

   at WinSCP.SessionLogReader.Read(LogReadFlags flags)
   at WinSCP.ElementLogReader.Read(LogReadFlags flags)
   at WinSCP.ElementLogReader.Read(LogReadFlags flags)
   at WinSCP.ElementLogReader.ReadToEnd(LogReadFlags flags)
   at WinSCP.Session.ExecuteCommand(String command)


Here is relevant excerpt from session log:
> 2012-04-05 20:11:17.078 Script: call RNFR /source/testx.zip

. 2012-04-05 20:11:17.078 Executing user defined command.
> 2012-04-05 20:11:17.078 RNFR /source/testx.zip
< 2012-04-05 20:11:17.093 Script: 350 File exists, ready for destination name.
< 2012-04-05 20:11:17.093 350 File exists, ready for destination name.
* 2012-04-05 20:11:17.093 (ExtException) File exists, ready for destination name.
. 2012-04-05 20:11:17.093 Script: Failed
> 2012-04-05 20:11:17.375 Script: call RNTO /source/testy.zip
. 2012-04-05 20:11:17.375 Executing user defined command.
> 2012-04-05 20:11:17.375 RNTO /source/testy.zip
< 2012-04-05 20:11:17.406 Script: 250 RNTO command successful.
< 2012-04-05 20:11:17.609 250 RNTO command successful.
. 2012-04-05 20:11:17.609 Getting current directory name.
> 2012-04-05 20:11:17.625 Script: exit
. 2012-04-05 20:11:17.625 Disconnected from server


Thanks in advance