locked
Azcopy - Not working when using string concatenation in StandardInput.WriteLine RRS feed

  • Question

  •   using (Process process2 = new Process())
                        {
                            process2.StartInfo = new ProcessStartInfo("cmd.exe")
                            {
                                RedirectStandardInput = true,
                                UseShellExecute = false,
                                WorkingDirectory = @"C:\azcopy",
                            };
                            process2.OutputDataReceived += p_OutputDataReceived;
                            process2.ErrorDataReceived += p_ErrorDataReceived;
                            process2.Start();
                            process2.StandardInput.WriteLine();

    //if we give entire input string within double quotes " " then working fine but concatenated string is not working 

                            p.StandardInput.WriteLine(@"AzCopy copy \\testserverab\AAbb.json  https://adlsgen2.dfs.core.windows.net/test2/FileUploads/AAbb.json.json --overwrite=true" );  // Working

    // Below Concatenated String is working fine in local machine BUT the same string is FAILING IN SERVER MACHINE  , tried multiple ways but no luck please help us why the concatenated string not working 

                 p.StandardInput.WriteLine(@"AzCopy copy" + @sourcefile + " "  + "https://adlsgen2.dfs.core.windows.net/" + " " + "test2/FileUploads/AAbb.json  --overwrite=true");  

                        }


    suresh sm





    • Edited by suresh sm Saturday, April 27, 2019 9:33 PM
    Saturday, April 27, 2019 6:26 AM

Answers

All replies

  • Can you please try to do a simple print of the  string @"AzCopy copy" + @sourcefile + " "  + "https://adlsgen2.dfs.core.windows.net/" + " " + "test2/FileUploads/AAbb.json  --overwrite=true"  and see what is missed there .

    Also are sure that the path from the server is accessible .

    Can you please do a very simple ping on from the server to the destination server and see if that is accessible?


    Thanks Himanshu

    Tuesday, April 30, 2019 10:00 PM
  • Thanks himanshu , we have identified that problem is due to concurrency settings. now working fine.

    suresh sm

    Wednesday, May 1, 2019 9:35 PM
  • Hi suresh,

    Glad to know that your issue has resolved. And thanks for sharing the solution, which might be beneficial to other community members reading this thread. 

    Thursday, May 2, 2019 4:48 AM
  •  There is another way to upload files  from on-premise machine to ADLS Gen2 through .Net C# Console AzCopy tool ( version 10)

    Step 1: Download AzCopy version 10

    Step 2: Place .exe file in any folder ( ex: c:\azcopy\azcopy.exe)

    Step 3: Include all these four environment variables with value

    AZCOPY_CRED_TYPE = "SharedKey";

    ACCOUNT_NAME = "testgen2";

    ACCOUNT_KEY = "testsdgasfdsa324324324afdsafwwrw34324324wfdsafsdfwrewr324234324243dfasdfdsfsdf=";

    AZCOPY_CONCURRENCY_VALUE=10

     Step 4:

    using (Process process = new Process())

                            {

                                process.StartInfo = new ProcessStartInfo("cmd.exe")

                                {

                                    RedirectStandardInput = true,

                                    UseShellExecute = false,

                                    WorkingDirectory = @"C:\azcopy"

    // Ensure right path is entered here or include the path in environment variables to run form any location

                                };

                                process.OutputDataReceived += p_OutputDataReceived;

                                process.ErrorDataReceived += p_ErrorDataReceived;

                                // start process

                                process.Start();

                                // send command to its input

                                process.StandardInput.WriteLine(builderParam.ToString());

                                //TESTED - WITH HARDCODE PATH

                                //p.StandardInput.Write(@"AzCopy copy \\sharedmachinename\FolderName\TestFileName.json https://testgen2.dfs.core.windows.net/Fileupload/data/TestFileName.json --overwrite=true" + p.StandardInput.NewLine);

                                process.StandardInput.WriteLine($"AzCopy copy {souceFileName} {destParamFile} --overwrite=true");

                            }


    suresh sm


    • Edited by suresh sm Tuesday, May 7, 2019 11:34 PM
    Tuesday, May 7, 2019 11:31 PM
  • Hi Suresh,

    Thank you for sharing your solution and experience here. It will be greatly beneficial for other community members who have similar questions.

    Wednesday, May 8, 2019 4:17 AM