GetRequestStream()抛出异常(GetRequestStream() throws an exception)
我正在尝试将文本文件上传到FTP服务器。
这是代码:
public void upload(string remoteFile, string localFile) { try { /* Create an FTP Request */ ftpRequest = (FtpWebRequest)WebRequest.Create(" ftp://Gamification.somee.com/test.txt"); //ftpRequest = (FtpWebRequest)FtpWebRequest.Create(host + "/" + remoteFile); /* Log in to the FTP Server with the User Name and Password Provided */ ftpRequest.Credentials = new NetworkCredential(user, pass); /* When in doubt, use these options */ ftpRequest.UseBinary = false; ftpRequest.UsePassive = true; ftpRequest.KeepAlive = false; /* Specify the Type of FTP Request */ ftpRequest.Method = WebRequestMethods.Ftp.UploadFile; /* Establish Return Communication with the FTP Server */ ftpStream = ftpRequest.GetRequestStream(); /* Open a File Stream to Read the File for Upload */ FileStream localFileStream = new FileStream(localFile, FileMode.Open); /* Buffer for the Downloaded Data */ byte[] byteBuffer = new byte[bufferSize]; int bytesSent = localFileStream.Read(byteBuffer, 0, bufferSize); /* Upload the File by Sending the Buffered Data Until the Transfer is Complete */ try { while (bytesSent != 0) { ftpStream.Write(byteBuffer, 0, bytesSent); bytesSent = localFileStream.Read(byteBuffer, 0, bufferSize); MessageBox.Show("succeded"); } } catch (Exception ex) { Console.WriteLine(ex.ToString()); } /* Resource Cleanup */ localFileStream.Close(); ftpStream.Close(); ftpRequest = null; } catch (Exception ex) { Console.WriteLine(ex.ToString()); } return; }
但该函数在运行此行时抛出异常
ftpStream = ftpRequest.GetRequestStream();
我认为URL中有问题,也许它与IP有关,但我无法解决。
I'm trying to upload a text file to an FTP server.
Here's the code:
public void upload(string remoteFile, string localFile) { try { /* Create an FTP Request */ ftpRequest = (FtpWebRequest)WebRequest.Create(" ftp://Gamification.somee.com/test.txt"); //ftpRequest = (FtpWebRequest)FtpWebRequest.Create(host + "/" + remoteFile); /* Log in to the FTP Server with the User Name and Password Provided */ ftpRequest.Credentials = new NetworkCredential(user, pass); /* When in doubt, use these options */ ftpRequest.UseBinary = false; ftpRequest.UsePassive = true; ftpRequest.KeepAlive = false; /* Specify the Type of FTP Request */ ftpRequest.Method = WebRequestMethods.Ftp.UploadFile; /* Establish Return Communication with the FTP Server */ ftpStream = ftpRequest.GetRequestStream(); /* Open a File Stream to Read the File for Upload */ FileStream localFileStream = new FileStream(localFile, FileMode.Open); /* Buffer for the Downloaded Data */ byte[] byteBuffer = new byte[bufferSize]; int bytesSent = localFileStream.Read(byteBuffer, 0, bufferSize); /* Upload the File by Sending the Buffered Data Until the Transfer is Complete */ try { while (bytesSent != 0) { ftpStream.Write(byteBuffer, 0, bytesSent); bytesSent = localFileStream.Read(byteBuffer, 0, bufferSize); MessageBox.Show("succeded"); } } catch (Exception ex) { Console.WriteLine(ex.ToString()); } /* Resource Cleanup */ localFileStream.Close(); ftpStream.Close(); ftpRequest = null; } catch (Exception ex) { Console.WriteLine(ex.ToString()); } return; }
but the function throws an exception when it's running this line
ftpStream = ftpRequest.GetRequestStream();
I think there's something wrong in the URL and maybe it's related to IP but I can't solve it.
原文:https://stackoverflow.com/questions/34521848
更新时间:2023-10-28 19:10
最满意答案
不,基本API不允许您在用户时间轴或搜索中返回那么远。 完整档案可作为Twitter的Gnip API之一提供。
No, the basic API doesn't let you go back that far either in a user timeline or in search. The full archive is available as one of Twitter's Gnip APIs.
相关问答
更多-
只获取包含图片的推文(使用Python的Twitter搜索API)(Get only tweets that contain images (Twitter search API with Python))[2022-05-07]
你能用Python中的TwitterSearch API构建一个自定义查询并执行它吗? 如果是的话,你可以使用“filter:images”作为查询的参数,以获得只有那些图像, 如此查询 ,但请注意,它使用php-api 或者,也许你可以使用“过滤器:媒体”(获取与媒体的所有推文)结合“ - 过滤器:视频”(删除视频),如果我没有错“过滤器:图像”返回的tweets有一个图像的URL Thanks for the recommendations, I somehow managed to do what I ... -
如何调用Twitter API来获取用户的所有推文,并仅通过图像?(How to call Twitter API to get all tweets by user and only with image?)[2023-04-20]
过滤器:图像应该是q参数的一部分,而不是单独的。 在这里看到文档。 https://dev.twitter.com/rest/public/search $ twitterapi '/1.1/search/tweets.json?include_entities=true&q=from%3Ajack filter%3Aimages' | jq -r '.statuses[] | [.entities.media[0].media_url, .text] | @tsv' http://pbs.twimg.co ... -
您可以使用user_timeline方法来提取多达3200个用户最近的Tweets。 如果这包括两个月前的推文,则表示没问题,但忙碌的帐户可能会在一段时间内更频繁地使用推文。 使用公共API无法搜索超过7天的Tweets。 You could use the user_timeline method to fetch up to 3200 of the user's most recent Tweets. If that includes Tweets from two months ago, you ar ...
-
来自Twitter的TOS : 通过在服务上或通过服务提交,发布或展示内容,您授予我们全球性,非独占性,免版税使用许可(有再许可权)以使用,复制,复制,处理,修改,修改,发布,传输,以任何和所有媒体或分发方法(现在已知或以后开发)显示和分发此类内容。 [提示] 本授权允许我们将您的推文提供给世界其他地区,并让其他人也这样做。 但你的是你的 - 你拥有你的内容。 换句话说,是的,你可以存储它们,并随意复制它们。 该页面还链接到API规则 ,这些规则有一些要求,例如归因推文,不编辑它们以改变其含义,以及在商业使 ...
-
400 Bad Request错误表示服务器无法理解您的请求。 在你的情况下,有一个错字,阻止请求通过(额外的% )。 尝试这个: const tweet = 'https://api.twitter.com/1.1/search/tweets.json?q=SamSchaeferSays'; function getUserTweet() { return axios.get(`${tweet}`, { headers: { 'Authorization': 'YOUR_OAUTH_HEADER' ...
-
twitter API搜索推文(twitter API search for tweets)[2022-03-15]
根据Twitter Search API文档,您无法进行所需的查询: https : //dev.twitter.com/rest/public/search Twitter Search API会搜索过去7天内发布的最新推文。 超过过去7天,您想要实现的目标只能通过在Twitter上手动搜索帐户来完成。 一种选择是使用https://webrecorder.io/ 滚动到您要记录或尝试捕获整个Feed的时间。 请注意自动滚动选项。 According to the The Twitter Search A ... -
Twitter搜索API - 是否可以返回未截断的推文?(Twitter Search API - Is it possible to return tweets that aren't truncated?)[2022-03-23]
最近Twitter改变了它显示推文的方式以及它们在API中的表现方式 - 请参阅https://dev.twitter.com/overview/api/upcoming-changes-to-tweets 您需要在查询结尾添加?tweet_mode=extended 。 这将使您获得所需的数据。 Recently Twitter changed how it displays tweets and how they're represented in the API - see https://dev.t ... -
不,基本API不允许您在用户时间轴或搜索中返回那么远。 完整档案可作为Twitter的Gnip API之一提供。 No, the basic API doesn't let you go back that far either in a user timeline or in search. The full archive is available as one of Twitter's Gnip APIs.
-
由于每个$tweet都是一个数组,所以你应该使用$tweet['text']而不是$tweet->text foreach($tweets->statuses as $tweet) { echo $tweet['text']; } 另外$tweets->statuses应该是$tweets['statuses'] $tweets->statuses $tweets['statuses'] 。 Since each $tweet is an array so you should use $twee ...
-
当您一起使用多个术语时,Twitter搜索默认执行AND操作。 即 https://dev.twitter.com/docs/api/1.1/get/search/tweets.json?q=from%3AJoeMayo%20%23twitterapi 仅返回来自JoeMayo并包含#twitterapi的推文。 您可以在Twitter的搜索页面上进行试验。 When you use multiple terms together, Twitter search performs an AND operat ...