public void UploadFileToServerWithPath(string FileName) { try { string virtualPath = Path.GetFileName(FileName); string[] path = SplitPath(Path.GetDirectoryName(FileName)); string targetPath = string.Empty; for (int i = 2; i < path.Length; i++) { targetPath += path[i] + "\\"; } using (Stream uploadStream = new FileStream(FileName, FileMode.Open)) { m_client.PutFileWithPath(new FileUploadMessage() { VirtualPath = virtualPath, TargetPath = targetPath, DataStream = uploadStream }); pCallback(1, m_ipAddress, "e", "e", "e", 1); } //File.Delete(FileName); } catch (Exception err) { throw (new SystemException(err.Message)); } }
private void UploadFileToServerWithPath(string FileName, DateTime startTimeToSend, ulong listNum, ulong fileNumber, ulong g360Index, string fileOwnerUserName, DateTime wtsDateTime) { string virtualPath = Path.GetFileName(FileName); string[] path = SplitPath(Path.GetDirectoryName(FileName)); string targetPath = string.Empty; for (int i = 2; i < path.Length; i++) { targetPath += path[i] + "\\"; } if (File.Exists(FileName) == false) { q1.MarkAsSent(); m_event.Set(); m_retryEvent.Set(); return; } using (Stream uploadStream = new FileStream(FileName, FileMode.Open)) { try { if (m_client != null && keepStorageClientConnectionOpen == false) { m_client.Close(); m_client = null; } Console.WriteLine("Connect to repository.."); m_currentUploadedFile = string.Empty; string strstartDate = DateTime.Now.AddYears(-10).ToString(FMT); m_currentUploadedDate = strstartDate; m_currentUploadedG360Index = 0; m_currentUploadedFileOwner = string.Empty; m_currentUploadedVirtualPath = string.Empty; m_currentUploadedTargetPath = string.Empty; if (m_verbose) { string msg = "Trying to connect to respository server.."; pCallback(150, m_clientIpAddress, string.Empty, string.Empty, msg, 1, DateTime.Now, 0, fileOwnerUserName); } if (m_client == null) { m_client = ConnectFileRepositoryServer(); } Console.WriteLine("Connection done, uploading file: " + FileName); m_uploadInProgress = true; DateTime startSendingTime = DateTime.Now; m_currentUploadedFile = FileName; strstartDate = DateTime.Now.ToString(FMT); m_currentUploadedDate = strstartDate; m_currentUploadedG360Index = g360Index; m_currentUploadedFileOwner = fileOwnerUserName; m_currentUploadedVirtualPath = virtualPath; m_currentUploadedTargetPath = targetPath; if (m_verbose) { string msg = "Connnected to repository , uploading file " + FileName + " (" + g360Index + ")"; Console.WriteLine(msg); pCallback(155, m_clientIpAddress, string.Empty, string.Empty, _GetCurrentUploadedFileInfo(), 1, DateTime.Now, 0, fileOwnerUserName); } // Create new FileInfo object and get the Length. FileInfo f = new FileInfo(m_currentUploadedFile); m_currentSizeOfFile = f.Length; m_client.PutFileWithPath(new FileUploadMessage() { VirtualPath = virtualPath, TargetPath = targetPath, DataStream = uploadStream, startTime = startTimeToSend, clientIpAddress = m_clientIpAddress, fieldGuid = m_fieldGuid, G360Index = g360Index, _fileOwnerUserName = fileOwnerUserName, AddDateToTargetFolder = m_addDateToTargetFolder, watsonDateTime = wtsDateTime, SizeOfFile = f.Length }); m_readyToSendNextFile.WaitOne(10000); } catch (Exception err) { m_uploadInProgress = false; Console.WriteLine(err.Message); pCallback(200, m_clientIpAddress, FileName, virtualPath, err.Message, 1, DateTime.Now, 0, fileOwnerUserName); m_uploadErrorStatus = err.Message; m_uploadErrorCount++; if (m_client != null) { m_client.Close(); m_client = null; } } } }