The problem is that put
copies a local file—that is, a file n your Windows box—to the server. As the documentation says:
put(self, localpath, remotepath, callback=None, confirm=True)
Copy a local file (localpath) to the SFTP server as remotepath.
Note that you're also specifying (or at least naming) the paths backward… but that doesn't really matter here, because neither one is actually a local path. So when you do this:
sftp.put(filepath, localpath)
… it's looking for a file named '/brass/prod/bin/chris/test1/km_cust'
on your Windows box, and of course it can't find such a file.
If you want to copy a remote file to a different remote file, you need to do something like this:
f = sftp.open(filepath)
sftp.putfo(f, localpath)
Or:
f = sftp.open(localpath, 'wx')
sftp.getfo(filepath, f)
Also, I'm guessing your filepath
is supposed to start with a /
.
However, this probably isn't what you wanted to do in the first place. Copying a file from the remote server to the remote server via sftp involves downloading all of the bytes to your Windows machine and then uploading them back to the remote machine. A better solution would be to just tell the machine to do the copy itself:
s.exec_command("cp '{}' '{}'".format(filepath, localfile))
s.close()
Note that in anything but the most trivial of cases, you're going to have to deal with the Channel
and its in/out/err and wait on its exit status. But I believe that for this case, you should be fine.