troubleshooting Question

Help with Python - Error generating from FTP script

Avatar of Isaiah Melendez
Isaiah Melendez asked on
ProgrammingPython
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/alr_to_ho.py", line 38, in <module>
    ftpTransmit()
  File "/Users/isaiah.melendez/Documents/python/alr_to_ho.py", line 34, in ftpTransmit
    sftp.put(ftpALR[i], 'C:\CBASYNC')
  File "/Users/isaiah.melendez/Documents/python/venv/lib/python3.7/site-packages/pysftp/__init__.py", line 364, in put
    confirm=confirm)
  File "/Users/isaiah.melendez/Documents/python/venv/lib/python3.7/site-packages/paramiko/sftp_client.py", 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/sftp_client.py", line 714, in putfo
    with self.file(remotepath, "wb") as fr:
  File "/Users/isaiah.melendez/Documents/python/venv/lib/python3.7/site-packages/paramiko/sftp_client.py", 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/sftp_client.py", line 813, in _request
    return self._read_response(num)
  File "/Users/isaiah.melendez/Documents/python/venv/lib/python3.7/site-packages/paramiko/sftp_client.py", line 865, in _read_response
    self._convert_status(msg)
  File "/Users/isaiah.melendez/Documents/python/venv/lib/python3.7/site-packages/paramiko/sftp_client.py", line 898, in _convert_status
    raise IOError(text)
OSError


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)
            #print(ftpALR)

# ftp transmission function
def ftpTransmit():
    # list ftp dir
    cnopts = pysftp.CnOpts()
    cnopts.hostkeys = None
    with pysftp.Connection(host='co2.cbapps.com', 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")
findFile()
ftpTransmit()

I have the user credentials being passed by a locker.py 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