Topic "Renaming Files on FTP"

Author Message
Lino
[View user's profile]

Joined: 2012-04-05
Posts: 3
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.

Code:
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:
Code:

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:
Code:

> 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
martin
[View user's profile]
Site Admin
Joined: 2002-12-10
Posts: 24994
Location: Prague, Czechia
Thanks for your post.

This issue has been added to the tracker:
https://winscp.net/tracker/show_bug.cgi?id=832

Request for native support for renaming files has been added too:
https://winscp.net/tracker/show_bug.cgi?id=833
_________________
Martin Prikryl
Lino
[View user's profile]

Joined: 2012-04-05
Posts: 3
Thanks a lot Martin, looking forward to it.
Advertisements

You can post new topics in this forum






Search Site

What is WinSCP?

It is award-winning SFTP client, SCP client, FTPS client and FTP client integrated into one software program for file transfer to FTP server or secure SFTP server. [More]

And it's free!

Donate

About donations

$9   $19   $49   $99

About donations

Recommend

WinSCP Privacy Policy

WinSCP License