如何从客户端接收文件并在c#中保存服务器上的文件 [英] how to receive file from clients and save file on server in c#
本文介绍了如何从客户端接收文件并在c#中保存服务器上的文件的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!
问题描述
我的问题是如何从客户端接收文件并将文件保存在服务器上
这是我的客户代码:
my problem is how to receive file from clients and save file on server
here is my client code:
using System;
using System.Collections.Generic;
using System.ComponentModel;
using System.Data;
using System.Drawing;
using System.Linq;
using System.Text;
using System.Windows.Forms;
using System.IO;
using System.Net;
using System.Net.Sockets;
namespace client
{
public partial class Form1 : Form
{
public Form1()
{
InitializeComponent();
}
private void button1_Click(object sender, EventArgs e)
{
OpenFileDialog ofd = new OpenFileDialog();
ofd.ShowDialog();
textBox1.Text = ofd.FileName;
}
private void button2_Click(object sender, EventArgs e)
{
Stream Fs = File.OpenRead(textBox1.Text);
Byte[] buffer = new Byte[Fs.Length];
Fs.Read(buffer, 0, buffer.Length);
TcpClient socket = new TcpClient("10.10.3.137", 10);
NetworkStream nw = socket.GetStream();
nw.Write(buffer, 0, buffer.Length);
nw.Close();
}
}
}
推荐答案
看看这个:表格设计师友好背景智能传输服务(BITS)包装 [ ^ ]
没有服务器?不,如果你的意思是软件服务器,无论它是什么 - FTP服务器,HTTP服务器,自定义网络服务器。实际上,这就是问如何在没有第二台PC的情况下将文件从一台客户端PC传输到另一台客户端PC? :-)
-SA
Without server? No, if you mean the software server, whatever it is — FTP server, HTTP server, custom network server. Practically, this is the same as to ask "How can I transfer files from one client PC to another client PC, without a second PC?" :-)
—SA
你可以看到这些......
http://www.csharp-examples.net/socket-send-receive/ [ ^ ]
http:/ /www.daniweb.com/software-development/csharp/threads/352484/transfer-file-from-client-to-server-using-sockets-using-c [ ^ ]
http://infynet.wordpress.com/tag / file-sending-using-c / [ ^ ]
http://stackoverflow.com/questions/3353984/sending-and-receiving-files-socket-programming-c-sharp [ ^ ]
You can see these..
http://www.csharp-examples.net/socket-send-receive/[^]
http://www.daniweb.com/software-development/csharp/threads/352484/transfer-file-from-client-to-server-using-sockets-using-c[^]
http://infynet.wordpress.com/tag/file-sending-using-c/[^]
http://stackoverflow.com/questions/3353984/sending-and-receiving-files-socket-programming-c-sharp[^]
这篇关于如何从客户端接收文件并在c#中保存服务器上的文件的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!
查看全文