2

I am able to connect the sftp with pysftp successfully, but getting error while downloading file as FileNotFoundError: [Errno 2] No such file. I also observed that the file is just creating at local path adding '?' along with extension. Below are more details.

File at ftp as Test_03132018080105.csv. File creating at Local path as Test_03132018080105.csv? with zero bytes

Code:

def get_move_on_ftp(ftpsource,localsource):
    if (os.stat(envvar.validfiles).st_size == 0) and (os.stat(envvar.invalidfiles).st_size == 0):
        print("There are no Source files on FTP.")
    else:
        srcinfo={'host':envvar.src_ftphost,'port':envvar.src_ftpport,'username':envvar.src_uname,'password':envvar.src_passwd}
        sftp = pysftp.Connection(**srcinfo)
        sftp.cwd(ftpsource)
        '''  Downloading Files   '''
        avail_files=open(envvar.validfiles,'r')
        for filename in avail_files:
            print(sftp.getcwd())
            #sftp.get(filename, preserve_mtime=True)
            print(filename) # for debug
            sftp.get(filename)
        sftp.close()

Error:

Traceback (most recent call last):
  File "my.py", line 96, in <module>
    main()
  File "my.py", line 92, in main
    config_file_read(config_file)
  File "my.py", line 85, in config_file_read
    get_move_on_ftp(ftpsource,localsource)
  File "my.py", line 61, in get_move_on_ftp
    sftp.get(filename)
  File "/home/username/miniconda3/lib/python3.6/site-packages/pysftp/__init__.py", line 249, in get
    self._sftp.get(remotepath, localpath, callback=callback)
  File "/home/username/miniconda3/lib/python3.6/site-packages/paramiko/sftp_client.py", line 770, in get
    size = self.getfo(remotepath, fl, callback)
  File "/home/username/miniconda3/lib/python3.6/site-packages/paramiko/sftp_client.py", line 746, in getfo
    file_size = self.stat(remotepath).st_size
  File "/home/username/miniconda3/lib/python3.6/site-packages/paramiko/sftp_client.py", line 460, in stat
    t, msg = self._request(CMD_STAT, path)
  File "/home/username/miniconda3/lib/python3.6/site-packages/paramiko/sftp_client.py", line 780, in _request
    return self._read_response(num)
  File "/home/username/miniconda3/lib/python3.6/site-packages/paramiko/sftp_client.py", line 832, in _read_response
    self._convert_status(msg)
  File "/home/username/miniconda3/lib/python3.6/site-packages/paramiko/sftp_client.py", line 861, in _convert_status
    raise IOError(errno.ENOENT, text)
FileNotFoundError: [Errno 2] No such file
learner
  • 119
  • 1
  • 2
  • 12

1 Answers1

0

Just add "/" in front of ftpsource. i.e. "/2020/Jan/10/". It should work

  • This does not provide an answer to the question. Once you have sufficient [reputation](https://stackoverflow.com/help/whats-reputation) you will be able to [comment on any post](https://stackoverflow.com/help/privileges/comment); instead, [provide answers that don't require clarification from the asker](https://meta.stackexchange.com/questions/214173/why-do-i-need-50-reputation-to-comment-what-can-i-do-instead). – Tyler2P Dec 03 '20 at 13:01