troubleshooting Question

Help with Python - Error generating from FTP script

Avatar of Isaiah Melendez
Isaiah Melendez asked on
8 Comments1 Solution72 ViewsLast Modified:
Hello, Experts,

I have a question to ask regarding a python script I have built to find a file, put in an array and SFTP that to a remote location that is running errors. The error I am getting is below.

Traceback (most recent call last):
  File "/Users/isaiah.melendez/Documents/python/", line 38, in <module>
  File "/Users/isaiah.melendez/Documents/python/", line 34, in ftpTransmit
    sftp.put(ftpALR[i], 'C:\CBASYNC')
  File "/Users/isaiah.melendez/Documents/python/venv/lib/python3.7/site-packages/pysftp/", line 364, in put
  File "/Users/isaiah.melendez/Documents/python/venv/lib/python3.7/site-packages/paramiko/", line 759, in put
    return self.putfo(fl, remotepath, file_size, callback, confirm)
  File "/Users/isaiah.melendez/Documents/python/venv/lib/python3.7/site-packages/paramiko/", line 714, in putfo
    with self.file(remotepath, "wb") as fr:
  File "/Users/isaiah.melendez/Documents/python/venv/lib/python3.7/site-packages/paramiko/", line 372, in open
    t, msg = self._request(CMD_OPEN, filename, imode, attrblock)
  File "/Users/isaiah.melendez/Documents/python/venv/lib/python3.7/site-packages/paramiko/", line 813, in _request
    return self._read_response(num)
  File "/Users/isaiah.melendez/Documents/python/venv/lib/python3.7/site-packages/paramiko/", line 865, in _read_response
  File "/Users/isaiah.melendez/Documents/python/venv/lib/python3.7/site-packages/paramiko/", line 898, in _convert_status
    raise IOError(text)

Python Code:
#import libraries
import os
import pysftp
from locker import *

# query for file function
alr_file = '/Users/isaiah.melendez/Documents/python/test'
#alr_file = 'C:\TBOffice\TBOLink\TEK\Export'
#prep list to store data in
ftpALR = []

ftp_un_dec = cipher_suite.decrypt(cipher_text2)
ftp_pw_dec = cipher_suite.decrypt(cipher_text)

#look for file and store in list and iterate
def findFile():

    for item in os.listdir(alr_file):
        if item.endswith('.mdb'):
            #ftpALR.append(alr_file + '\\' + item)
            ftpALR.append(alr_file + '/' + item)

# ftp transmission function
def ftpTransmit():
    # list ftp dir
    cnopts = pysftp.CnOpts()
    cnopts.hostkeys = None
    with pysftp.Connection(host='', username=ftp_un_dec.decode('utf-8'), password=ftp_pw_dec.decode('utf-8'), port=2222, cnopts=cnopts) as sftp:

        length = len(ftpALR)

        for i in range(length):
            sftp.put(ftpALR[i], 'C:\CBASYNC')
    print("Transmission Success")

I have the user credentials being passed by a file and imported into this file.

Let me know your thoughts as to why this might be happening?
Join the community to see this answer!
Join our exclusive community to see this answer & millions of others.
Unlock 1 Answer and 8 Comments.
Join the Community
Learn from the best

Network and collaborate with thousands of CTOs, CISOs, and IT Pros rooting for you and your success.

Andrew Hancock - VMware vExpert
See if this solution works for you by signing up for a 7 day free trial.
Unlock 1 Answer and 8 Comments.
Try for 7 days

”The time we save is the biggest benefit of E-E to our team. What could take multiple guys 2 hours or more each to find is accessed in around 15 minutes on Experts Exchange.

-Mike Kapnisakis, Warner Bros