UPDATE: copying a file from serverA to serverB

Ok, just talked with our server administrator, and all the permissions are set on both servers. Now I get the error message: Network path not found. I gave him dummy server names for this demo if I use the wrong names. Should I try to use IP addresses and still get this error. What am I doing wrong?

'File.Copy("\\sever.name.local.mil\pdf\audits\2009-05-19audit-09-01.pdf", "\\sever.name.remote.mil\sigar_cms\pdf\audits\2009-05-19audit-09-01.pdf")' 

Can someone give me some advice, this is reflected in my brain.

thanks

+4
source share
6 answers
 Dim FilePath As String = "\\sigar" & "\pdf\audits\" & "" 

This will create the string \\sigar\pdf\audits\ . You can simplify the line:

 Dim FilePath As String = "\\sigar\pdf\audits\" 

Server.MapPath used to translate the virtual path to your website so that the file path is on the server. In other words, you do not need to use it at all. Change the second line to:

 FileUpload1.SaveAs(FilePath + FileName) 

If this does not work, it is possible that the identifier in which your application pool is running does not have permission to write the file at the specified path. Try sigar permissions for resources and / or files on sigar .

Update

To simply copy the file, use File.Copy :

 File.Copy("\\serverA\path\to\file", "\\serverB\path\to\file") 
+3
source

SOLVED: I figured it out. I intended to use the network path that was used to map the drive. Forgot to use the US dollar sign.

  ''# Save files to disk FileUpload1.SaveAs(Server.MapPath("../pdf/audits/" & FileName)) ''# Local Path Dim localPath As String = "\\localserver\folder$\pdf\audits\" ''# Remote Path Dim remotePath As String = "\\remoteserver\folder$\pdf\audits\" ''# Copy from Local to Remote servers System.IO.File.Copy(localPath + FileName, remotePath + FileName) 
+2
source

There are several errors in the published code. If you have more code, I would recommend publishing it. With that said, based on what I see, reading this MS article will answer your question - as it is currently expressed.

Write a text file ( Basic File IO )

This sample code uses the StreamWriter class to create and write to a file. If you have an existing file, you can open it in the same way.

 Dim writer As StreamWriter = _ New StreamWriter("c:\KBTest.txt") writer.WriteLine("File created using StreamWriter class.") writer.Close() 
0
source

Assuming the two servers are on the same local network and you have the appropriate access, you should be able to use the File.Copy method and use UNC for each server / path.

If the situation is a little more complicated than just copying a file between two peer servers, you may need to use FTP or SSH as the transport method.

0
source

Since your tags are , I am assuming this is in a web application running in the application pool in IIS.

Your first step is for your application pool user account to have write permissions to another account. By default, this account is similar to IIS_USR .

The second step is to save the file to the second server.

 Dim FilePath As String = "\\sigar\pdf\audits\" Dim FileName As String = "MyFile.txt" FileUpload1.SaveAs(String.Format("{0}{1}",FilePath, FileName)) 

You can also create your own recording method.

 Dim SourcePath As String = "C:\foo\pdf\audits\" Dim FileName As String = "MyFile.txt" Dim FileToCopy As String = String.Format("{0}{1}",SourcePath, FileName) Dim DestPath As String = "\\sigar\pdf\audits\" System.IO.File.Copy(FileToCopy, DestPath) 
0
source

@Gee I adapted your code to copy from one place on the server to another place on the same server. this code worked. Do it first in your environment - just to be sure.

It seems to me that this is some kind of problem with access to the network. Cross domains, user or group permissions or restrictions, etc.

 Imports System.IO File.Copy("\\CHI-CSD-06.mycompany.local\temp1\testfile.txt", "\\CHI-CSD-06.mycompany.local\temp2\testfile.txt") 
0
source

Source: https://habr.com/ru/post/1446092/


All Articles