Example #1
0
        private void SftpUpload(string filename, string localfolder, string ftppath)
        {
            SFTPHelper SFTP = new SFTPHelper(ftpserverURL, ftpname, ftppassword);

            try
            {
                SetText("成功连接服务器,尝试上传" + filename + "\r\n");
                bool      res    = true;
                ArrayList result = new ArrayList();
                if (filename.EndsWith("/"))
                {
                    res = SFTP.UploadFolder(Environment.CurrentDirectory + "/" + localroot + "/" + localfolder + "/" + filename, ftproot + "/" + ftppath + "/" + filename, ref result);
                }
                else
                {
                    res = SFTP.UploadFile(Environment.CurrentDirectory + "/" + localroot + "/" + localfolder + "/" + filename, ftproot + "/" + ftppath + "/" + filename);
                }
                if (res)
                {
                    SetText(filename + "上传成功\r\n");
                    SFTP.Disconnect();
                }
                else
                {
                    SetText(filename + "上传失败\r\n");
                }
            }
            catch (Exception ex)
            {
                SetText("出现错误:" + ex.ToString() + "\r\n");
            }
        }
Example #2
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");
            }
        }