Skip to content

Instantly share code, notes, and snippets.

@robla
Created July 18, 2016 00:18
Show Gist options
  • Save robla/28a322a1ad73cb16b9e6edc8bc70a484 to your computer and use it in GitHub Desktop.
Save robla/28a322a1ad73cb16b9e6edc8bc70a484 to your computer and use it in GitHub Desktop.
print the sftp URL of a file from shell
#!/usr/bin/python
import os
import socket
import sys
import urllib
def sftppath(file):
fqdn=socket.getfqdn()
fullpath=os.path.realpath(os.path.expanduser(file))
return "sftp://" + fqdn + urllib.quote(fullpath)
if len(sys.argv)>1:
for arg in sys.argv[1:]:
print sftppath(arg)
else:
print sftppath(".")
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment