Beispiel #1
0
        private void ListOperation()
        {
            SFTPHelper SFTP = new SFTPHelper(ftpserverURL, ftpname, ftppassword);

            try
            {
                SFTP.Connect();
                if (SFTP.Connected)
                {
                    SetText("成功连接服务器,尝试列出所有文件\r\n");
                    ArrayList filelist = SFTP.GetFolderContents(textRfolder.Text, "");
                    if (filelist == null)
                    {
                        SetText("Exception. 请确保目录填写正确,如根目录需填入\"/\"\r\n");
                    }
                    else
                    {
                        foreach (string file in filelist)
                        {
                            SetText(">>" + file + "\r\n");
                        }
                    }
                    SFTP.Disconnect();
                }
            }
            catch (Exception ex)
            {
                SetText("出现错误:" + ex.ToString() + "\r\n");
            }
        }
Beispiel #2
0
        private void SftpDownload(string filename, string localpath, string ftppath)//下载操作
        {
            SFTPHelper SFTP = new SFTPHelper(ftpserverURL, ftpname, ftppassword);

            try
            {
                SFTP.Connect();
                if (SFTP.Connected)
                {
                    SetText("成功连接服务器,尝试下载" + filename + "\r\n");
                    bool      res    = true;
                    ArrayList result = new ArrayList();
                    if (filename.EndsWith("/"))
                    {
                        res = SFTP.DownloadFolder(ftproot + "/" + ftppath + "/" + filename, Environment.CurrentDirectory + "/" + localroot + "/" + localpath + "/" + filename, ref result);
                    }
                    else
                    {
                        res = SFTP.DownloadFile(ftproot + "/" + ftppath + "/" + filename, Environment.CurrentDirectory + "/" + localroot + "/" + localpath + "/" + filename);
                    }
                    if (res)
                    {
                        SetText("下载成功\r\n");
                    }
                    else
                    {
                        SetText("下载失败\r\n");
                    }
                    SFTP.Disconnect();
                }
            }
            catch (Exception ex)
            {
                SetText("出现错误:" + ex.ToString() + "\r\n");
            }
        }