-1

Presently I am working on python and I a need to get some files from other network using the psftp command as below:

import os
psftpCmd='psftp sftp.example.com -l user -pw pass'
os.system(psftpCmd)

But when run the above code I get the following error:

sh: psftp: command not found

Can I know whats wrong with the command and how to execute a psftp command as shown above?

Shawn Chin
  • 84,080
  • 19
  • 162
  • 191
Shiva Krishna Bavandla
  • 25,548
  • 75
  • 193
  • 313

1 Answers1

0

Assuming that psftp is installed and you have access to the shell:

Find the full path to the executabe. Run which psftp from the command line and replace the value in your string. For example, if which psftp returns "/usr/local/bin/psftp" then try:

import os
psftpCmd='/usr/local/bin/psftp sftp.example.com -l user -pw pass'
os.system(psftpCmd)

Though really you should be using a library instead of running this through a system() call. Even subprocess.popen would be better.

moopet
  • 6,014
  • 1
  • 29
  • 36
  • thanks for ur answer, actually the above code has been running on windows machine succesfully. But now i implementing the same on fedora(linux machine), so i am din't to know to use "usr/local/bin" before command, i will try the above method and let u know about it – Shiva Krishna Bavandla Sep 11 '12 at 12:53
  • @shivakrishna: it's unlikely your linux machine has a command called `psftp`, since that's a part of PuTTY, and is completely unnecessary on machines with real ssh and sftp clients. – Wooble Sep 11 '12 at 12:55
  • which: no psftp in (/usr/lib64/ccache:/usr/local/bin:/usr/bin:/bin:/usr/local/sbin:/usr/sbin:/sbin) – Shiva Krishna Bavandla Sep 11 '12 at 12:57
  • Yes, as wooble says it's unlikely, but you didn't specify what the command was supposed to be. You're out of luck on this one. Instead, if your purpose is to FTP some files, use a library dedicated to this. Use ftplib for ftp for example, or check http://stackoverflow.com/questions/432385/sftp-in-python-platform-independent for an SFTP solution. – moopet Sep 11 '12 at 13:35