Sign Up

Sign Up to our social questions and Answers Engine to ask questions, answer people’s questions, and connect with other people.

Have an account? Sign In

Have an account? Sign In Now

Sign In

Login to our social questions & Answers Engine to ask questions answer people’s questions & connect with other people.

Sign Up Here

Forgot Password?

Don't have account, Sign Up Here

Forgot Password

Lost your password? Please enter your email address. You will receive a link and will create a new password via email.

Have an account? Sign In Now

You must login to ask a question.

Forgot Password?

Need An Account, Sign Up Here

Please briefly explain why you feel this question should be reported.

Please briefly explain why you feel this answer should be reported.

Please briefly explain why you feel this user should be reported.

Sign InSign Up

The Archive Base

The Archive Base Logo The Archive Base Logo

The Archive Base Navigation

  • SEARCH
  • Home
  • About Us
  • Blog
  • Contact Us
Search
Ask A Question

Mobile menu

Close
Ask a Question
  • Home
  • Add group
  • Groups page
  • Feed
  • User Profile
  • Communities
  • Questions
    • New Questions
    • Trending Questions
    • Must read Questions
    • Hot Questions
  • Polls
  • Tags
  • Badges
  • Buy Points
  • Users
  • Help
  • Buy Theme
  • SEARCH
Home/ Questions/Q 7869871
In Process

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: June 3, 20262026-06-03T01:27:04+00:00 2026-06-03T01:27:04+00:00

I have a Python code that uses Paramiko. #!/usr/bin/env python import paramiko username =

  • 0

I have a Python code that uses Paramiko.

#!/usr/bin/env python

import paramiko

username = ('user')
password = ('1234')
hostname = ('test-server.com')
ports = 22
localD = ('/var/tmp/testxxxxxxxx.tar.gz')
remoteD = ('/var/tmp/testxxxxxxxx.tar.gz')



paramiko.util.log_to_file('/tmp/paramiko.log')
transport = paramiko.Transport((hostname, ports))
transport.connect(username = username, password = password)
sftp = paramiko.SFTPClient.from_transport(transport)
sftp.put(remotepath=remoteD, localpath=localD)

sftp.close()
transport.close()

With this code, the local-dir and the remote-dir should be equals. if not “file not found”
How can I change or use another remote-dir different to local-dir?
Example:

localD = ('/var/tmp/testxxxxxxxx.tar.gz')
remoteD = ('/home/user/testxxxxxxxx.tar.gz')

Thank you

  • 1 1 Answer
  • 0 Views
  • 0 Followers
  • 0
Share
  • Facebook
  • Report

Leave an answer
Cancel reply

You must login to add an answer.

Forgot Password?

Need An Account, Sign Up Here

1 Answer

  • Voted
  • Oldest
  • Recent
  • Random
  1. Editorial Team
    Editorial Team
    2026-06-03T01:27:05+00:00Added an answer on June 3, 2026 at 1:27 am

    Since the error message says ‘No such file or directory‘, I’d first check to make sure the directory exists on remote system and is writable by the credentials you’re using. The SFTPClient class has all sorts of other methods you can call to verify the existence of target paths and create them if they don’t exist yet.

    For example, calling the stat() method passing in the destination path should give you back a tuple the same as that returned by os.stat. Try running this script (I just hacked up a little path check routine and dropped it into your script):

    #!/usr/bin/env python
    
    import paramiko
    
    username = ('user')
    password = ('1234')
    hostname = ('test-server.com')
    ports = 22
    localD = ('/var/tmp/testxxxxxxxx.tar.gz')
    remoteD = ('/var/tmp/testxxxxxxxx.tar.gz')
    
    def check(sftp, path):
        parts = path.split('/')
        for n in range(2, len(parts) + 1):
            path = '/'.join(parts[:n])
            print 'Path:', path,
            sys.stdout.flush()
            try:
                s = sftp.stat(path)
                print 'mode =', oct(s.st_mode)
            except IOError as e:
                print e
    
    paramiko.util.log_to_file('/tmp/paramiko.log')
    transport = paramiko.Transport((hostname, ports))
    transport.connect(username = username, password = password)
    sftp = paramiko.SFTPClient.from_transport(transport)
    check(sftp, remoteD)
    
    sftp.close()
    transport.close()
    

    Output should be something like this:

    Path: /var mode = 040755
    Path: /var/tmp mode = 040700
    Path: /var/tmp/testxxxxxxxx.tar.gz [Errno 2] No such file
    

    The mode numbers will most likely differ, but you shouldn’t get “No such file” error on any of the parts of the path other than the file name. If you do, then it probably means you need to construct the path down to the point where you want to put the file using sftp.mkdir()

    • 0
    • Reply
    • Share
      Share
      • Share on Facebook
      • Share on Twitter
      • Share on LinkedIn
      • Share on WhatsApp
      • Report

Sidebar

Related Questions

I have some Python code that uses Paramiko to grab build files from a
I have Python code that uses the with keyword (new in 2.6) and I
I'm looking at existing python code that heavily uses Paramiko to do SSH and
I have some old python code that uses the pywin32 extensions. Starting out with
I'm testing a piece of Python code that uses subprocess.call(), so I have no
I'm just learning about python. I'm fairly new. I have the following code that
I have a python ndarray temp in some code I'm reading that suffers this:
I am reading cpython code for python 3k and I have noticed, that __missing__
I have some code in a python string that contains extraneous empty lines. I
I'm trying to test some python code that uses urllib2 and lxml. I've seen

Explore

  • Home
  • Add group
  • Groups page
  • Communities
  • Questions
    • New Questions
    • Trending Questions
    • Must read Questions
    • Hot Questions
  • Polls
  • Tags
  • Badges
  • Users
  • Help
  • SEARCH

Footer

© 2021 The Archive Base. All Rights Reserved
With Love by The Archive Base

Insert/edit link

Enter the destination URL

Or link to existing content

    No search term specified. Showing recent items. Search or use up and down arrow keys to select an item.