sftp connect
# Default port is 22
sftp your_user@your_server_ip_or_remote_hostname
# Connexion with a custom port
sftp -oPort=custom_port your_user@your_server_ip_or_remote_hostname
sftp connect
# Default port is 22
sftp your_user@your_server_ip_or_remote_hostname
# Connexion with a custom port
sftp -oPort=custom_port your_user@your_server_ip_or_remote_hostname
SFTP Connect
using System;
using System.Linq;
using WinSCP;
class Program
{
static int Main(string[] args)
{
try
{
// Setup session options
SessionOptions sessionOptions = new SessionOptions
{
Protocol = Protocol.Sftp,
HostName = "example.com",
UserName = "user",
Password = "mypassword",
SshHostKeyFingerprint = "ssh-rsa 2048 xxxxxxxxxxx...=",
};
using (Session session = new Session())
{
// Connect
session.Open(sessionOptions);
const string remotePath = "/home/user";
const string localPath = @"C:\downloaded";
// Get list of files in the directory
RemoteDirectoryInfo directoryInfo = session.ListDirectory(remotePath);
// Select the most recent file
RemoteFileInfo latest =
directoryInfo.Files
.Where(file => !file.IsDirectory)
.OrderByDescending(file => file.LastWriteTime)
.FirstOrDefault();
// Any file at all?
if (latest == null)
{
throw new Exception("No file found");
}
// Download the selected file
session.GetFileToDirectory(latest.FullName, localPath);
}
return 0;
}
catch (Exception e)
{
Console.WriteLine("Error: {0}", e);
return 1;
}
}
}
Copyright © 2021 Codeinu
Forgot your account's password or having trouble logging into your Account? Don't worry, we'll help you to get back your account. Enter your email address and we'll send you a recovery link to reset your password. If you are experiencing problems resetting your password contact us