Ad

Ftp Does Not Transfer Complete File

- 1 answer

I have the following code to transfer a file to another linux machine:

import ftplib
session = ftplib.FTP('192.168.1.111','ubuntu','ubuntu')
file = open('/home/nehal/darknet/yolo.weights','rb')                  # file to send
print(session.pwd())
print(ftplib.FTP.dir(session))
session.storbinary('STOR /home/ubuntu/yolo.weights',file)                  #send the file
file.close()
session.quit()


The file yolo.weights is of 209MB and only few MBs are transferred.

I also tried transferring a file of 30MB but only a few MBs get transferred and it seems like no data is transferred thereafter.
What could be the issue?

Ad

Answer

When using STOR you should pass only the filename and not the path. So to ensure the file ends up in the correct place, use .cwd() to first specify the target directory:

import ftplib

session = ftplib.FTP('192.168.1.111','ubuntu','ubuntu')
file = open('/home/nehal/darknet/yolo.weights','rb')                  # file to send
print(session.pwd())
print(ftplib.FTP.dir(session))

session.cwd('/home/ubunto')
session.storbinary('STOR yolo.weights',file)                  #send the file

file.close()
session.quit()    

Or you could try as follows:

import ftplib

session = ftplib.FTP('192.168.1.111', 'ubuntu', 'ubuntu')
file = open('/home/nehal/darknet/yolo.weights', 'rb')

with session, file:
    print(session.pwd())
    print(ftplib.FTP.dir(session))
    session.cwd('/home/ubunto')
    session.storbinary('STOR yolo.weights', file)
Ad
source: stackoverflow.com
Ad