How can I extract the hostname from: hostname:/file_name ? For example in ngs.pradhi.com:/upload, I want to extract ngs.pradhi.com from it
hostname:/file_name
ngs.pradhi.com:/upload
ngs.pradhi.com
The string in your example isn't a URL, so you won't be able to use the standard URL module (urlparse) to parse it. Here is how you can do it by hand:
urlparse
In [43]: path = 'ngs.pradhi.com:/upload' In [44]: path.split(':')[0] Out[44]: 'ngs.pradhi.com'
For SSH, take a look at paramiko.