Andrius
Andrius

Reputation: 21118

ftplib - move file to another directory? (with rename)

I run this:

ftps.rename(rec.path+field_name, rec.archive_path+field_name)\
print 'passed'

To move file to another directory as I need to archive it. This line of code runs fine, without errors (I also added print check to see if it really runs). But files are not moved. Its like nothing happened. I don't get it why.

Also I can't seem to move the file using GUI too. For example I connect to ftp using Ubuntu network interface and then try to manually cut and paste the file. Then I see this message (and progress bar): preparing to move 1 file, but it just disappears and nothing happens. No errors, nothing.

Directories in ftp are located this way:

/root/
  /source/
  /archive/

I'm trying to move file from source to archive

to be exact, ftp server is sharefile.com (sharefileftp.com)

P.S. Maybe its possible to copy file to another directory then (as a workaround)? It seems I can at least manually copy the file. So I could just copy it and then delete one from original directory

Upvotes: 2

Views: 5221

Answers (1)

Yunkai Xiao
Yunkai Xiao

Reputation: 301

This is how I did it.

Goto your destination dir first:

FTP.cwd('/home/destination/')

Then execute move (rename from and rename to) command:

FTP.sendcmd('RNFR ' + 'Full/Path/Source/File')
FTP.sendcmd('RNTO ' + 'filename')

These are FTP command that does the job, same way you would use in an console.

I would assume you can cwd into destination and use FTP.rename in the same way, it could be just some permission issue or the way FTP is designed to work.

Upvotes: 1

Related Questions