Re: Strange problem when not in debugger



Here it goes:

using System;
using System.Collections.Generic;
using System.ComponentModel;
using System.Data;
using System.Drawing;
using System.Text;
using System.Windows.Forms;
using System.IO;
using System.Net;
using Microsoft;

namespace WebBackup
{
public partial class frmBackup : Form
{
private string huidigWeb;
private string huidigMap;

private WebBackupForm f1 = new WebBackupForm();

public frmBackup(WebBackupForm F1)
{
f1 = F1;
InitializeComponent();
}

public WebBackupForm F1
{
get { return f1; }
}

/// <summary>
/// Method to upload the specified file to the specified FTP Server
/// </summary>
/// <param name="filename">file full name to be uploaded</param>
///
/// filename = local
/// FTnaam = FTP naam
private void Upload(string filename, string FTnaam)
{
// MessageBox.Show("in upload.");
FileInfo fileInf = new FileInfo(filename);
// MessageBox.Show("file: " + filename + " upload: " + FTnaam);

string uri = "ftp://"; + F1.FTPserver + "/"; // fileInf.Name;
FtpWebRequest reqFTP;
MessageBox.Show("Uri :" + uri);

// Create FtpWebRequest object from the Uri provided

reqFTP = (FtpWebRequest)FtpWebRequest.Create(new Uri(uri)); //"ftp://"; + F1.FTPserver + "/" + FTnaam));

// MessageBox.Show("ReqFTP");
//fileInf.Name));
MessageBox.Show("After uri");

// Provide the WebPermission Credintials
reqFTP.Credentials = new NetworkCredential(F1.FTPnaam, F1.FTPpassword);

// By default KeepAlive is true, where the control connection is not closed
// after a command is executed.
reqFTP.KeepAlive = false;

// Specify the command to be executed.
reqFTP.Method = WebRequestMethods.Ftp.UploadFile;

// Specify the data transfer type.
reqFTP.UseBinary = true;

// Notify the server about the size of the uploaded file
reqFTP.ContentLength = fileInf.Length;

// Calculate the progressbar

long len = fileInf.Length;
len = len / 2048;
if (len > 0)
len = 1000 / len;
else len = 1;
if (len <= 0)
len = 1;

int max = (int)len;

// Show count

long Teller = fileInf.Length;
lblTeller.Text = Teller.ToString();

// The buffer size is set to 2kb
int buffLength = 2048;
byte[] buff = new byte[buffLength];
int contentLen;

// Opens a file stream (System.IO.FileStream) to read the file to be uploaded
FileStream fs = fileInf.OpenRead();
this.lblBestand.Text = FTnaam;

// try
// {
// Stream to which the file to be upload is written
Stream strm = reqFTP.GetRequestStream();

// Read from the file stream 2kb at a time
contentLen = fs.Read(buff, 0, buffLength);

// Till Stream content ends
while (contentLen != 0)
{
// Write Content from the file stream to the FTP Upload Stream
strm.Write(buff, 0, contentLen);
contentLen = fs.Read(buff, 0, buffLength);
progressBar.Value = (int)len;
progressBar.PerformStep();
len += max;
if (len >= 1000) len = 0;
Teller -= (long)contentLen;
lblTeller.Text = Teller.ToString();
this.Refresh();
}

// Close the file stream and the Request Stream
strm.Close();
fs.Close();
}

public void DeleteFTP
(string
fileName)
{
try
{
string uri = "ftp://"; + F1.FTPserver + "/" + fileName;
FtpWebRequest reqFTP;
reqFTP = (FtpWebRequest)FtpWebRequest.Create(new Uri("ftp://"; + F1.FTPserver + "/" + fileName));

reqFTP.Credentials = new NetworkCredential(F1.FTPnaam, F1.FTPpassword);
reqFTP.KeepAlive = false;
reqFTP.Method = WebRequestMethods.Ftp.DeleteFile;

string result = String.Empty;
FtpWebResponse response = (FtpWebResponse)reqFTP.GetResponse();
long size = response.ContentLength;
Stream datastream = response.GetResponseStream();
StreamReader sr = new StreamReader(datastream);
result = sr.ReadToEnd();
sr.Close();
datastream.Close();
response.Close();
}
catch (Exception ex)
{
// MessageBox.Show(ex.Message, "FTP 2.0 Delete");
}
}

private
void makedir
(string
dirName)
{
/* string dir = dirName.Replace('/', '\\');
dir = "H:\\" + dir;
Directory.CreateDirectory(dir);

return;
*/
// MessageBox.Show("In makedir.");
FtpWebRequest reqFTP;
try
{
// dirName = name of the directory to create.
reqFTP = (FtpWebRequest)FtpWebRequest.Create(new Uri("ftp://"; + F1.FTPserver + "/" + dirName));
reqFTP.Method = WebRequestMethods.Ftp.MakeDirectory;
reqFTP.UseBinary = true;
reqFTP.Credentials = new NetworkCredential(F1.FTPnaam, F1.FTPpassword);
FtpWebResponse response = (FtpWebResponse)reqFTP.GetResponse();
Stream ftpStream = response.GetResponseStream();

ftpStream.Close();
response.Close();
}
catch (Exception ex)
{
// MessageBox.Show(ex.Message, " Directory fout");
}
}

private
void btnAnnuleer_Click
(object
sender,
EventArgs e)
{
this.Close();
}

private
void btnStart_Click
(object
sender,
EventArgs e)
{
int i;
int Positie = 0;
string Mappen = "";
string WebMappen = "";
string backup = "/backup/";

lblBackup.Text = "Bezig met de backup naar " + F1.FTPserver;
this.Refresh();
DeleteFTP("backup/");
// makedir(backup);

// Ga dooe de lijst heen van mappen die door de gebruiker aangeklikt zijn om te
// backuppen

for (i = 0; i < F1.BestandsLijst.Items.Count; i++)
{
Mappen = F1.BestandsLijst.Items[i].ToString();
Positie = Mappen.IndexOf('\\');
WebMappen = backup;

WebMappen += Mappen.Substring(Positie + 1);
WebMappen = WebMappen.Replace('\\', '/');
string dirHulp = "";

// Maak eerst de mappen die niet met bestanden moetn worden gechreven
foreach (string dirPart in WebMappen.Split('/'))
{
dirHulp += dirPart;
dirHulp += "/";
if (dirHulp.Length > 1)
{
makedir(dirHulp);
}
}

DirectoryInfo dirinf = new DirectoryInfo(Mappen);
huidigWeb = dirHulp;
huidigMap = Mappen;

schrijfNaarWeb(Mappen);
// string[] bestanden = GetFileList();
}
lblBestand.Text = "Klaar met uploaden.";
this.Refresh();
}

public
void schrijfNaarWeb
(string
directory)
{
if (!Directory.Exists(directory))
{
throw new FileNotFoundException("De map bestaat niet. " + directory);
}

try
{
string[] files = Directory.GetFiles(directory);

foreach (string file in files)
{
if (file != null)
{
string copyfrom = file;
string copyto;
string webfile = file.Replace('\\', '/');
int wfpos = webfile.IndexOf('/');
webfile = "/backup/" + webfile.Substring(wfpos + 1);
copyto = webfile.Replace('/', '\\');
copyto = "H:\\" + copyto;
lblBackup.Text = copyfrom;
this.Refresh();
// File.Copy(copyfrom, copyto);
Upload(file, webfile);
}
}

string[] dirs = Directory.GetDirectories(directory);

foreach (string dir in dirs)
{
string webdir = dir.Replace('\\', '/');
int wdpos = webdir.IndexOf('/');
webdir = "/backup/" + webdir.Substring(wdpos + 1);
makedir(webdir);

schrijfNaarWeb(dir);
}
}
catch (Exception ex)
{
MessageBox.Show("Exeception :" + ex.Message);
}
}

}
}

"Peter Duniho" <NpOeStPeAdM@xxxxxxxxxxxxxxxx> schreef in bericht news:op.t9axudlu8jd0ej@xxxxxxxxxxxxxxxxxxxxxxx
On Tue, 08 Apr 2008 09:41:02 -0700, Rinaldo <zwartehoofdpiet@xxxxxxxxxxxxxxxxxx> wrote:

Positive that the string return the same value. Even when I hardcode the URL + path without calling any variable I get the same error.

The bottom line: until you post a concise-but-complete code example that reliably reproduces the problem, you're unlikely to get an actual answer.

.



Relevant Pages

  • Getting Error in Login() method in FtpConnection Class
    ... private static int BUFFER_SIZE = 512; ... private static Encoding ASCII = Encoding.ASCII; ... private string server = "localhost"; ... public void Login() ...
    (microsoft.public.dotnet.languages.csharp)
  • Re: Problem with FTP
    ... > private static Encoding ASCII = Encoding.ASCII; ... > private string message = null; ... > private int port = 21; ... > public void Login() ...
    (microsoft.public.pocketpc.developer)
  • Versioning question
    ... bool SaveActivity(Activity a, string username, string password); ... ActivityTypeID, DateTime FollowUpDate, int TimeSpent, bool isOpen, ... private DateTime _FollowUpDate; ...
    (microsoft.public.dotnet.framework.remoting)
  • Re: Trouble with custom InputStream being used by Readers
    ... wrong with my Stream. ... He'll fill his buffer. ... private final Object lock = new Object; ... public synchronized int read ...
    (comp.lang.java.programmer)
  • Re: Why doesnt std::cin choke on this?
    ... when I was writing a user-driven test program for a data structure I ... You read an int. ... it simpler then checking the stream for it's ... read in a string, this becomes trivial. ...
    (comp.lang.cpp)