本文将分享如何从客户端复制http服务器上的文件?的详细内容,并且还将对如何从客户端复制http服务器上的文件夹进行详尽解释,此外,我们还将为大家带来关于Android客户端使用okhttp上传文件p
本文将分享如何从客户端复制http服务器上的文件?的详细内容,并且还将对如何从客户端复制http服务器上的文件夹进行详尽解释,此外,我们还将为大家带来关于Android客户端使用okhttp上传文件php服务器、asp.net http服务器推送到客户端、c# – 如何在FTP服务器上复制文件?、c# – 是否可以通过http将数据从客户端传输到服务器?的相关知识,希望对你有所帮助。
本文目录一览:- 如何从客户端复制http服务器上的文件?(如何从客户端复制http服务器上的文件夹)
- Android客户端使用okhttp上传文件php服务器
- asp.net http服务器推送到客户端
- c# – 如何在FTP服务器上复制文件?
- c# – 是否可以通过http将数据从客户端传输到服务器?
如何从客户端复制http服务器上的文件?(如何从客户端复制http服务器上的文件夹)
在过去,我使用了一个ftp服务器,通过客户端的“ftp”连接,“GET”将远程机器上的一个文件复制到本地机器上。
是否有可能做到这一点,但与服务器只运行一个HTTP服务器?
服务器: GoAhead Web服务器 。
Windows上的客户端和http服务器。
副本可以从浏览器启动,也可以在客户端上写入一个单独的程序。 (即 – 任何窗口API调用从http服务器复制文件?)
(另外,这些文件可能不在http根目录中,但是服务器上的其他地方……可以这样吗?)
如何以编程方式检查networking驱动器是否已映射?
你最喜欢的g ++选项是什么?
是否可以增加一个窗口的边框区域来调整窗口的大小?
我可以在Windows控制台使用asp.net web项目文件c#
gethostbyname()或getnameinfo()如何在后台工作?
自定义Windows皮肤,
boost :: asio如何实现定时数据包发送function?
Windows内存和页面文件的使用情况
如何将质询密码编码到证书请求中
编译发布版本后,我的应用程序开始变得怪异
HTTP服务器将只提供位于站点的文档根目录中的文件。 如果你想获取文件根目录之外的文件,你必须有一个脚本从服务器(PHP,perl,cgi等等)提供这个文件,或者找到一些获取这个文件的方法在文档根目录“里面”。
要下载站点文档根目录下的文件,只需点击指向该文件的url – 这就是HTTP的核心点 – 您只需从站点下载内容即可。
HTTP服务器也不会接受没有中间脚本来处理的上传。 如果他们这样做,你可以上传任何你想要的文件到任何服务器,在任何地方。
其他人提到的HTTP服务器是真的,但GoAhead Web服务器不是一个HTTP服务器。 它提供了许多其他的功能。 在补丁的帮助下,文件上传似乎是可能的。 更多信息:
https://embedthis.com/goahead/
为此,使用WebDav 。
Android客户端使用okhttp上传文件php服务器
为了更好的在应对网络访问,最近学习了一下okhttp,感觉挺方便使用的,首先要使用okhttp,需要在项目中导入okhttp-x.x.x.jar okhttputils-x_x_x.jar okio-x.x.x.jar 这三个jar包,下面贴出Android端和服务器端关键代码:
private void uplodeImage(File mFile) { //mFile一个真实存在的图片文件 if (!mFile.exists()) { Toast.makeText(MainActivity.this, "文件不存在,请修改文件路径", Toast.LENGTH_SHORT).show(); return; } OkHttpUtils.post() .url(UPLODE_URL) .addFile("file", mFile.getName(), mFile) .build() .execute(new Callback<string>() { @Override public void onError(Call arg0, Exception arg1) { System.out.println("上传文件失败"); info.setText("REEOR:upload error!"); } @Override public void onResponse(String arg0) { //System.out.println(arg0); //上传成功返回文件在服务器上的唯一路径,将此路径保存到数据库中 info.setText(arg0); //这里会返回一个包含上传文件在服务器上的唯一路径,上传成功后将这个字符串保存到数据库中去 } @Override public String parseNetworkResponse(Response arg0) throws Exception { // TODO Auto-generated method stub return arg0.body().string(); } }) ; }</string>
<?php class upload{ protected $fileName; protected $maxSize; protected $allowMime; protected $allowExt; protected $uploadPath; protected $imgFlag; protected $fileInfo; protected $error; protected $ext; /** * @param string $fileName * @param string $uploadPath * @param string $imgFlag * @param number $maxSize * @param array $allowExt * @param array $allowMime */ public function __construct($fileName='myFile',$uploadPath='./uploads',$imgFlag=true,$maxSize=5242880,$allowExt=array('jpeg','jpg','png','gif'),$allowMime=array('image/jpeg','image/png','image/gif')){ $this->fileName=$fileName; $this->maxSize=$maxSize; $this->allowMime=$allowMime; $this->allowExt=$allowExt; $this->uploadPath=$uploadPath; $this->imgFlag=$imgFlag; $this->fileInfo=$_FILES[$this->fileName]; } /** * 检测上传文件是否出错 * @return boolean */ protected function checkError(){ if(!is_null($this->fileInfo)){ if($this->fileInfo[''error'']>0){ switch($this->fileInfo[''error'']){ case 1: $this->error=''超过了PHP配置文件中upload_max_filesize选项的值''; break; case 2: $this->error=''超过了表单中MAX_FILE_SIZE设置的值''; break; case 3: $this->error=''文件部分被上传''; break; case 4: $this->error=''没有选择上传文件''; break; case 6: $this->error=''没有找到临时目录''; break; case 7: $this->error=''文件不可写''; break; case 8: $this->error=''由于PHP的扩展程序中断文件上传''; break; } return false; }else{ return true; } }else{ $this->error=''文件上传出错''; return false; } } /** * 检测上传文件的大小 * @return boolean */ protected function checkSize(){ if($this->fileInfo[''size'']>$this->maxSize){ $this->error=''上传文件过大''; return false; } return true; } /** * 检测扩展名 * @return boolean */ protected function checkExt(){ $this->ext=strtolower(pathinfo($this->fileInfo[''name''],PATHINFO_EXTENSION)); if(!in_array($this->ext,$this->allowExt)){ $this->error=''不允许的扩展名''; return false; } return true; } /** * 检测文件的类型 * @return boolean */ protected function checkMime(){ if(!in_array($this->fileInfo[''type''],$this->allowMime)){ $this->error=''不允许的文件类型''; return false; } return true; } /** * 检测是否是真实图片 * @return boolean */ protected function checkTrueImg(){ if($this->imgFlag){ if(!@getimagesize($this->fileInfo[''tmp_name''])){ $this->error=''不是真实图片''; return false; } return true; } } /** * 检测是否通过HTTP POST方式上传上来的 * @return boolean */ protected function checkHTTPPost(){ if(!is_uploaded_file($this->fileInfo[''tmp_name''])){ $this->error=''文件不是通过HTTP POST方式上传上来的''; return false; } return true; } /** *显示错误 */ protected function showError(){ return (Array( ''rType''=>-30, ''rMessage''=>$this->error ) ); } /** * 检测目录不存在则创建 */ protected function checkUploadPath(){ if(!file_exists($this->uploadPath)){ mkdir($this->uploadPath,0777,true); } } /** * 产生唯一字符串 * @return string */ protected function getUniName(){ return md5(uniqid(microtime(true),true)); } /** * 上传文件 * @return string */ public function uploadFile(){ if($this->checkError()&&$this->checkSize()&&$this->checkExt()&&$this->checkMime()&&$this->checkTrueImg()&&$this->checkHTTPPost()){ $this->checkUploadPath(); $this->uniName=$this->getUniName(); $this->destination=$this->uploadPath.''/''.$this->uniName.''.''.$this->ext; if(@move_uploaded_file($this->fileInfo[''tmp_name''], $this->destination)){ return Array( ''rType'' => 0, ''rMessage'' => $this->destination ); }else{ $this->error=''文件移动失败''; $this->showError(); } }else{ return $this->showError(); } } }
<?php require_once 'upload.class.php'; header("Content-type:text/html;charset=utf8"); $up = new upload('filename'); echo json_encode($up->uploadFile(),JSON_UNESCAPED_UNICODE);
以上就介绍了Android客户端使用okhttp上传文件php服务器,包括了方面的内容,希望对PHP教程有兴趣的朋友有所帮助。
asp.net http服务器推送到客户端
Gmail似乎做了很好的轮询服务器更新的电子邮件,甚至他们的聊天程序工作很好(所有在我的网络浏览器工作)。任何想法,最好的方式来做这样的事情,但使用asp.net?
编辑:
如果我必须轮询,我想要每2或3秒轮询服务器。所以我不知道如何做到这一点,而不会使Web服务器笨重的使用。
解决方法
看到我的其他答案在这里: Instant notifications like Facebook
c# – 如何在FTP服务器上复制文件?
var request = (FtpWebRequest)WebRequest.Create("ftp://www.mysite.com/test.jpg"); request.Credentials = new NetworkCredential(user,pass); request.Method = WebRequestMethods.Ftp.Rename; request.Renameto = "testrename.jpg" request.GetResponse().Close(); FtpWebResponse resp = (FtpWebResponse)request.GetResponse();
但是,没有复制文件的方法.你会如何复制文件?
解决方法
static void Main(string[] args) { copyFile("countrylist.csv","MySample.csv","username","password#"); } public static bool copyFile(string fileName,string Filetocopy,string userName,string password) { try { FtpWebRequest request = (FtpWebRequest)WebRequest.Create("ftp://ftp.mysite.net/" + fileName); request.Method = WebRequestMethods.Ftp.DownloadFile; request.Credentials = new NetworkCredential(userName,password); FtpWebResponse response = (FtpWebResponse)request.GetResponse(); Stream responseStream = response.GetResponseStream(); Upload("ftp://ftp.mysite.net/" + Filetocopy,ToByteArray(responseStream),userName,password); responseStream.Close(); return true; } catch { return false; } } public static Byte[] ToByteArray(Stream stream) { MemoryStream ms = new MemoryStream(); byte[] chunk = new byte[4096]; int bytesRead; while ((bytesRead = stream.Read(chunk,chunk.Length)) > 0) { ms.Write(chunk,bytesRead); } return ms.ToArray(); } public static bool Upload(string FileName,byte[] Image,string FtpUsername,string FtpPassword) { try { System.Net.FtpWebRequest clsRequest = (System.Net.FtpWebRequest)System.Net.WebRequest.Create(FileName); clsRequest.Credentials = new System.Net.NetworkCredential(FtpUsername,FtpPassword); clsRequest.Method = System.Net.WebRequestMethods.Ftp.UploadFile; System.IO.Stream clsstream = clsRequest.GetRequestStream(); clsstream.Write(Image,Image.Length); clsstream.Close(); clsstream.dispose(); return true; } catch { return false; } }
这会将文件下载到流中,然后上载它.
c# – 是否可以通过http将数据从客户端传输到服务器?
因为服务器是托管的,所以我没有能力使用套接字 – 只是http.
我知道在服务器端,如果我连接到客户端,我可以使用持久连接并只写入响应流.
但是有没有办法反向执行此操作,其中客户端与服务器具有持久连接并且正在写入请求流?
澄清:
我不必将此客户端 – >服务器通信作为持久性http连接完成,我只是想知道是否可能,只是因为我可以与我计划的服务器 – >客户端持久性http连接具有对称性.
从我听到的情况来看,听起来我应该只能做单独的http帖子并实现相同或类似的延迟.
解决方法
技术上可以从客户端 – >服务器执行持久的http连接,但是没有人实现它,因为使用创建单个http请求的常规方法似乎足够快,可以满足每个人的需求.
这就是我最终做的事情,只需使用WebRequest.Create和HttpWebRequest类,并相信框架正在处理KeepAlive.在我的原型中看起来足够快,尽管现实世界的表现还有待观察.
我们今天的关于如何从客户端复制http服务器上的文件?和如何从客户端复制http服务器上的文件夹的分享就到这里,谢谢您的阅读,如果想了解更多关于Android客户端使用okhttp上传文件php服务器、asp.net http服务器推送到客户端、c# – 如何在FTP服务器上复制文件?、c# – 是否可以通过http将数据从客户端传输到服务器?的相关信息,可以在本站进行搜索。
本文标签: