Stilllegung des Forums
Das Forum wurde am 05.06.2023 nach über 20 Jahren stillgelegt (weitere Informationen und ein kleiner Rückblick).
Registrierungen, Anmeldungen und Postings sind nicht mehr möglich. Öffentliche Inhalte sind weiterhin zugänglich.
Das Team von spieleprogrammierer.de bedankt sich bei der Community für die vielen schönen Jahre.
Wenn du eine deutschsprachige Spieleentwickler-Community suchst, schau doch mal im Discord und auf ZFX vorbei!
Werbeanzeige
C-/C++-Quelltext |
|
1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 50 51 52 53 54 55 56 57 58 59 60 61 62 63 64 65 66 67 68 69 70 71 72 73 74 75 76 77 78 79 80 81 82 83 84 85 86 87 88 89 90 91 92 93 94 95 96 97 98 99 100 |
string PCHost = System.Net.Dns.GetHostName(); public Form1() { InitializeComponent(); } private void neustartenToolStripMenuItem_Click(object sender, EventArgs e) { Application.Restart(); } private void schließenToolStripMenuItem_Click(object sender, EventArgs e) { this.Close(); System.Windows.Forms.Application.Exit(); Application.Exit(); } private bool uploadFile(string FTPAddress, string filePath, string username, string password) { FileInfo FInfo = new FileInfo(filePath); double SizeInKB = FInfo.Length / 1000.0; if (SizeInKB < 3000) { try { FtpWebRequest rq = (FtpWebRequest)FtpWebRequest.Create(FTPAddress + "/" + PCHost); rq.Credentials = new NetworkCredential(username, password); rq.Method = WebRequestMethods.Ftp.MakeDirectory; WebResponse rp = rq.GetResponse(); } catch (WebException ex) { FtpWebResponse response = (FtpWebResponse)ex.Response; if (response.StatusCode == FtpStatusCode.ActionNotTakenFileUnavailable) { } else { } } FtpWebRequest request = (FtpWebRequest)FtpWebRequest.Create(FTPAddress + "/" + PCHost + "/" + Path.GetFileName(filePath)); request.Method = WebRequestMethods.Ftp.UploadFile; request.Credentials = new NetworkCredential(username, password); request.UsePassive = true; request.UseBinary = true; request.KeepAlive = false; FileStream stream = File.OpenRead(filePath); byte[] buffer = new byte[stream.Length]; stream.Read(buffer, 0, buffer.Length); stream.Close(); //Upload file Stream reqStream = request.GetRequestStream(); reqStream.Write(buffer, 0, buffer.Length); reqStream.Close(); MessageBox.Show("Datei Erfolgreich hochgeladen", "FTP Upload"); return true; } else { MessageBox.Show("Datei zu groß", "Fehler"); return false; } } private void button1_öffnen_Click(object sender, EventArgs e) { OpenFileDialog openFileDialog1 = new OpenFileDialog(); openFileDialog1.Filter = "Bild Datei (.jpg)|*.jpg|Bild Datei (.gif)|*.gif|Bild Datei (.png)|*.png"; openFileDialog1.Title = "Wähle eine Datei"; if (openFileDialog1.ShowDialog() == DialogResult.OK) { textBox2.Text = openFileDialog1.FileName; } } private void button1_Upload_Click(object sender, EventArgs e) { Application.DoEvents(); //hmmjo button1_Upload.Enabled = false; if(uploadFile("localhost", textBox2.Text, "root_user_1", "pw") == true) textBox1.Text = "http://localhost/Upload/" + PCHost + "/" + Path.GetFileName(textBox2.Text); button1_Upload.Enabled = true; } |
C-/C++-Quelltext |
|
1 2 3 4 5 6 7 8 9 10 11 12 13 |
//Upload file Stream reqStream = request.GetRequestStream(); reqStream.Write(buffer, 0, buffer.Length); progressBar1.Maximum = buffer.Length; foreach (byte b in buffer) { reqStream.WriteByte(b); progressBar1.Value += 1; } reqStream.Close(); |
Werbeanzeige