如何在c#中使用FTP上传文件到另一个系统 [英] How to Upload A file INTO another system using FTP in c#

查看:92
本文介绍了如何在c#中使用FTP上传文件到另一个系统的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

可以给出正确值的任何指南LIKE(HOST,USERNAME,PASSWORD)



我得到这样的例外: SOCKET EXCEPTION CAUGHT



Could any guide for giving right values LIKE(HOST,USERNAME,PASSWORD)

I am Getting this exception like:SOCKET EXCEPTION CAUGHT

static string host = "ftp://10.10.10.147/C:/";
        static string user="DIPL/SivaRamGopal.v";
        static string password="123456aA";
        static string path = "SubscribersList.csv";
        static List<string> files = new List<string>();
        static string dest_dir = "";
        static bool is_anonymous = false;
        static bool rename_destination = false;
        static bool show_help = false;

        static readonly ILog log = LogManager.GetLogger(typeof(Program));

        static void Main(string[] args)
        {
            using (var db = new Provisioning.Data.ProvisioningWorkUnit())
            {

                
                
                var list = db.FullfillmentServiceTrackLog.Get(x=>x.IsAPI==false);
              
                FileStream stream = new FileStream("SubscribersList.csv", FileMode.Create);

                ExcelWriter writer = new ExcelWriter(stream);
                writer.BeginWrite();

                writer.WriteCell(0, 0, "Msisdn");
                writer.WriteCell(0, 1, "ServiceType");
                writer.WriteCell(0, 2, "DateOfRequest");
                int count = 1;


                foreach (var item in list)
                {
                    writer.WriteCell(count, 0, item.Msisdn);
                    writer.WriteCell(count, 1, item.ServiceType);
                    writer.WriteCell(count, 2, item.CreatedOn.ToString());
                    count++;

                }
                
                writer.EndWrite();
                stream.Close();
                writer = null;
                stream = null;
            }
            try
            {
                FTPClient.FtpClient ftp = new FTPClient.FtpClient(host, user, password);
                Console.WriteLine("Connecting to ftp server {0}", ftp.Server);
                ftp.Login();
                Console.WriteLine("Connnected to ftp server.");
                ftp.Upload(path);
                log.InfoFormat(string.Format("Uploaded successfully"));
                Console.WriteLine("Uploaded to ftp server");

            }

推荐答案

因为您使用的是我们一无所知的自定义FTPClient库,所以任何人都不可能告诉你问题是什么。



如果你有来自某个供应商的FTPClient库,你是最好的来源信息是该供应商。



如果您自己编写,我们需要查看登录方法的相关源代码。
Since you''re using a custom FTPClient library that we know nothing about, it''s impossible for anyone to tell you what the problem is.

If you''ve got that FTPClient library from some vendor, you''re best source of information is that vendor.

If you wrote it yourself, we''d need to see the relevent source code for the login method.


如何:使用FTP上传文件 [ ^ ]

并查看这些主题

在C#中捕获套接字异常 [ ^ ]

以及你的catch / finally异常处理部分在哪里
How to: Upload Files with FTP[^]
and have a look at these threads
Catching a Socket Exception in C#[^]
and where is your catch/finally part of the exception handling


这篇关于如何在c#中使用FTP上传文件到另一个系统的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆