Authentication with PPK key in SSH.NET

SSH.NET does not support .ppk key files. You have to use PuTTYgen to convert the .ppk key to OpenSSH format. See How to convert SSH keypairs generated using PuTTYgen (Windows) into key-pairs used by ssh-agent and Keychain (Linux). Original answer, before the question was edited: You are using multifactor private key and keyboard interactive authentication … Read more

List files on SFTP server matching wildcard in Python using Paramiko

The glob will not magically start working with a remote server, just because you have instantiated SSHClient before. You have to use Paramiko API to list the files, like SFTPClient.listdir: import fnmatch sftp = client.open_sftp() for filename in sftp.listdir(‘/home/test’): if fnmatch.fnmatch(filename, “*.txt”): print filename You can also use a regular expression for the matching, if … Read more

Batch file for PuTTY/PSFTP file transfer automation

You need to store the psftp script (lines from open to bye) into a separate file and pass that to psftp using -b switch: cd “C:\Program Files (x86)\PuTTY” psftp -b “C:\path\to\script\script.txt” Reference: https://the.earth.li/~sgtatham/putty/latest/htmldoc/Chapter6.html#psftp-option-b EDIT: For username+password: As you cannot use psftp commands in a batch file, for the same reason, you cannot specify the username … Read more

scp or sftp copy multiple files with single command

Copy multiple files from remote to local: $ scp [email protected]:/some/remote/directory/\{a,b,c\} ./ Copy multiple files from local to remote: $ scp foo.txt bar.txt [email protected]:~ $ scp {foo,bar}.txt [email protected]:~ $ scp *.txt [email protected]:~ Copy multiple files from remote to remote: $ scp [email protected]:/some/remote/directory/foobar.txt \ [email protected]:/some/remote/directory/ Source: http://www.hypexr.org/linux_scp_help.php

SFTP file transfer using Java JSch

The most trivial way to upload a file over SFTP with JSch is: JSch jsch = new JSch(); Session session = jsch.getSession(user, host); session.setPassword(password); session.connect(); ChannelSftp sftpChannel = (ChannelSftp) session.openChannel(“sftp”); sftpChannel.connect(); sftpChannel.put(“C:/source/local/path/file.zip”, “/target/remote/path/file.zip”); Similarly for a download: sftpChannel.get(“/source/remote/path/file.zip”, “C:/target/local/path/file.zip”); You may need to deal with UnknownHostKey exception.