#1
  1. No Profile Picture
    Registered User
    Devshed Newbie (0 - 499 posts)

    Join Date
    Dec 2012
    Posts
    3
    Rep Power
    0

    FTP to OS390 Mainframe


    I'm uploading a file to the mainframe using the following code:

    sftp = ftplib.FTP('server','user','password')
    fp = open('TestAFP.log','rb')
    directory = 'abc.test.'
    fname = 'afptext'
    sftp.storlines('STOR ' + "'" + directory + fname + "'".encode("utf-8"), fp)
    fp.close()
    sftp.quit()

    On the mainframe everything looks good except for spanish characters. I'm seeing the following espaC1ol instead of Espaņol.

    Is there a way to specify the correct codec so these special characters are transferred correctly?

    Thanks,
  2. #2
  3. Contributing User
    Devshed Demi-God (4500 - 4999 posts)

    Join Date
    Aug 2011
    Posts
    4,997
    Rep Power
    481
    Is there a binary mode? Use that. If I were using the ftp command
    $ ftp
    :login crud:
    ftp> binary
    200 Switching to Binary mode.
    ftp>
    [code]Code tags[/code] are essential for python code and Makefiles!
  4. #3
  5. No Profile Picture
    Registered User
    Devshed Newbie (0 - 499 posts)

    Join Date
    Dec 2012
    Posts
    3
    Rep Power
    0
    Thanks for the suggestion b49P23TIvg. I tried the storbinary method and it delivers it to the mainframe but is not in a readable format. There might me some options on the mainframe to convert the binary into readable text and preserve the spanish characters.
  6. #4
  7. Contributing User
    Devshed Demi-God (4500 - 4999 posts)

    Join Date
    Aug 2011
    Posts
    4,997
    Rep Power
    481
    Then in python maybe you read the file in as binary into bytes objects then use the encode (or decode) functions trying various encodings. As I recall, python supports hundreds of encodings. Maybe.
    [code]Code tags[/code] are essential for python code and Makefiles!
  8. #5
  9. No Profile Picture
    Registered User
    Devshed Newbie (0 - 499 posts)

    Join Date
    Dec 2012
    Posts
    3
    Rep Power
    0
    Yep. I tried about 15 different encodings without any luck yet.
  10. #6
  11. Contributing User
    Devshed Newbie (0 - 499 posts)

    Join Date
    May 2012
    Location
    39N 104.28W
    Posts
    158
    Rep Power
    3
    The only thing I can think of to do is to change any characters whose ord(char) is greater than 127 to something else. It won't be any more readable but it will be on purpose.

IMN logo majestic logo threadwatch logo seochat tools logo