问:
C++ socket option reuse port
I have a problem with a c++ socket.

I'm using CAsyncSocket from MFC that i want to join a multicast group.

Also I need to have multiple listener on this group and here is where i get in trouble.

I found some examples on the web but it doesn't seems to work.

Here is my code:

```<code>//create socket on port 17233
BOOL bRet = Create(17233,SOCK_DGRAM, FD_READ);

//set reuse socket option
BOOL bMultipleApps = TRUE;
bRet = SetSockOpt(SO_REUSEADDR, (void*)&bMultipleApps, sizeof(BOOL), SOL_SOCKET);

//join multicast group
ip_mreq m_mrMReq;           // Contains IP and interface of the host group
m_mrMReq.imr_multiaddr.s_addr = inet_addr((LPCSTR)"224.30.0.1");    /* group addr */
m_mrMReq.imr_interface.s_addr = htons(INADDR_ANY);      /* use default */

int uRes =setsockopt(m_hSocket, IPPROTO_IP, IP_ADD_MEMBERSHIP, (char FAR *)&m_mrMReq, sizeof(m_mrMReq));
</code>```

There are no errors when i run this.

But when i try to run another instance of the app it fails to create a new socket on that port because the port is in use.

I have done this in C# and it worked fine like this:

```<code>IPEndPoint ipep = new IPEndPoint(IPAddress.Any, port);
s.SetSocketOption(SocketOptionLevel.Socket, SocketOptionName.ReuseAddress, 1);
s.Bind(ipep);
IPAddress ip = IPAddress.Parse(mcastGroup);
s.SetSocketOption(SocketOptionLevel.IP, SocketOptionName.AddMembership, new MulticastOption(ip, IPAddress.Any));
s.SetSocketOption(SocketOptionLevel.IP,SocketOptionName.MulticastTimeToLive, int.Parse("1"));
</code>```

So if any body sees a problem with my code or have some tips i will gladly appreciated.

EDIT 1:

Is CAsyncSocket a TCP socket?

EDIT 2:
After reading Can two applications listen to the same port?

I think i made a confusion. I need a Multicast UDP port that can be access by multiple application using SO_REUSEADDR

Edit for Clarification:

```<code>BOOL bRet = Create(17233,SOCK_DGRAM, FD_READ)
</code>```

Creates an UDP socket and bind's to to port 17223.

For SetSockOpt(SO_REUSEADDR, (void*)&bMultipleApps, sizeof(BOOL), SOL_SOCKET); to work you need to set it before binding  as @Hasturkun said.

The final working code looks like this:

```<code>    BOOL bRet = Socket(SOCK_DGRAM, FD_READ);
    if(bRet != TRUE)
    {
        UINT uErr = GetLastError();
        std::cout<<"Error:"<<uErr<<std::endl;
        return FALSE;
    }else{
        std::cout<<"Create sock: OK"<<std::endl;
    }

    //add reuse
    BOOL bMultipleApps = TRUE;      /* allow reuse of local port if needed */
    SetSockOpt(SO_REUSEADDR, (void*)&bMultipleApps, sizeof(BOOL), SOL_SOCKET);

    //bind
    bRet = Bind(17233, NULL);
    if(bRet != TRUE)
    {
        UINT uErr = GetLastError();
        std::cout<<"Error(BIND):"<<uErr<<std::endl;
    }else{
        std::cout<<"BIND sock: OK"<<std::endl;
    }
</code>```

Thanks,

Gabriel

;

答:
This happens, i guess, because you are binding a client socket to a specific port and address. Maybe on its constructor:

BOOL bRet = Create(17233,SOCK_DGRAM, FD_READ);

You should not binding a client socket to an address. Let windows manage this for you. You should have a option to not create the socket passing a specific port, or if you do not, you should create the socket using another port.

Also, the BOOL bMultipleApps = TRUE; option does not work the way you think it does. It sets a linger option in the socket, but once created and listening, the socket (i mean the socket port) cannot be used in other applications no mather what you do.

Check this out: so-linger-and-closing-socketswinsock

EDIT:

I also dont know that the value of port in your c# code:

IPEndPoint ipep = new IPEndPoint(IPAddress.Any, port);

Are you sure that port does not get a different value every time you run the app?

As I said, try to create the socket in a different port to see what happens. Google for so_linger to know what it means.

EDIT 2:

Take a look at: Can two application listen to the same port?

EDIT 3:

Maybe your c# code:

```<code>IPEndPoint ipep = new IPEndPoint(IPAddress.Any, port);
</code>```

is binding the address to a different NIC. Do you have 2 nics at the same computer? If you do, you can bind the same port in both of them.

EDIT 4:

Example of using UDP sockets: Sending & Receiving UDP Datagrams with MFC's CAsyncSocket

Title: C++ socket option reuse port

Body:
I have a problem with a c++ socket.

I'm using CAsyncSocket from MFC that i want to join a multicast group.

Also I need to have multiple listener on this group and here is where i get in trouble.

I found some examples on the web but it doesn't seems to work.

Here is my code:

//create socket on port 17233
BOOL bRet = Create(17233,SOCK_DGRAM, FD_READ);

//set reuse socket option
BOOL bMultipleApps = TRUE;
bRet = SetSockOpt(SO_REUSEADDR, (void*)&bMultipleApps, sizeof(BOOL), SOL_SOCKET);

//join multicast group
ip_mreq m_mrMReq;           // Contains IP and interface of the host group
m_mrMReq.imr_multiaddr.s_addr = inet_addr((LPCSTR)"224.30.0.1");    /* group addr */
m_mrMReq.imr_interface.s_addr = htons(INADDR_ANY);      /* use default */

int uRes =setsockopt(m_hSocket, IPPROTO_IP, IP_ADD_MEMBERSHIP, (char FAR *)&m_mrMReq, sizeof(m_mrMReq));

There are no errors when i run this.

But when i try to run another instance of the app it fails to create a new socket on that port because the port is in use.

I have done this in C# and it worked fine like this:

IPEndPoint ipep = new IPEndPoint(IPAddress.Any, port);
s.SetSocketOption(SocketOptionLevel.Socket, SocketOptionName.ReuseAddress, 1);
s.Bind(ipep);
IPAddress ip = IPAddress.Parse(mcastGroup);
s.SetSocketOption(SocketOptionLevel.IP, SocketOptionName.AddMembership, new MulticastOption(ip, IPAddress.Any));
s.SetSocketOption(SocketOptionLevel.IP,SocketOptionName.MulticastTimeToLive, int.Parse("1"));

So if any body sees a problem with my code or have some tips i will gladly appreciated.

EDIT 1:

Is CAsyncSocket a TCP socket?

EDIT 2:
After reading Can two applications listen to the same port?

I think i made a confusion. I need a Multicast UDP port that can be access by multiple application using SO_REUSEADDR

Edit for Clarification:

BOOL bRet = Create(17233,SOCK_DGRAM, FD_READ)

Creates an UDP socket and bind's to to port 17223.

For SetSockOpt(SO_REUSEADDR, (void*)&bMultipleApps, sizeof(BOOL), SOL_SOCKET); to work you need to set it before binding  as @Hasturkun said.

The final working code looks like this:

    BOOL bRet = Socket(SOCK_DGRAM, FD_READ);
    if(bRet != TRUE)
    {
        UINT uErr = GetLastError();
        std::cout<<"Error:"<<uErr<<std::endl;
        return FALSE;
    }else{
        std::cout<<"Create sock: OK"<<std::endl;
    }

    //add reuse
    BOOL bMultipleApps = TRUE;      /* allow reuse of local port if needed */
    SetSockOpt(SO_REUSEADDR, (void*)&bMultipleApps, sizeof(BOOL), SOL_SOCKET);

    //bind
    bRet = Bind(17233, NULL);
    if(bRet != TRUE)
    {
        UINT uErr = GetLastError();
        std::cout<<"Error(BIND):"<<uErr<<std::endl;
    }else{
        std::cout<<"BIND sock: OK"<<std::endl;
    }

Thanks,

Gabriel

;

Body:
This happens, i guess, because you are binding a client socket to a specific port and address. Maybe on its constructor:

BOOL bRet = Create(17233,SOCK_DGRAM, FD_READ);

You should not binding a client socket to an address. Let windows manage this for you. You should have a option to not create the socket passing a specific port, or if you do not, you should create the socket using another port.

Also, the BOOL bMultipleApps = TRUE; option does not work the way you think it does. It sets a linger option in the socket, but once created and listening, the socket (i mean the socket port) cannot be used in other applications no mather what you do.

Check this out: so-linger-and-closing-socketswinsock

EDIT:

I also dont know that the value of port in your c# code:

IPEndPoint ipep = new IPEndPoint(IPAddress.Any, port);

Are you sure that port does not get a different value every time you run the app?

As I said, try to create the socket in a different port to see what happens. Google for so_linger to know what it means.

EDIT 2:

Take a look at: Can two application listen to the same port?

EDIT 3:

Maybe your c# code:

IPEndPoint ipep = new IPEndPoint(IPAddress.Any, port);

is binding the address to a different NIC. Do you have 2 nics at the same computer? If you do, you can bind the same port in both of them.

EDIT 4:

Example of using UDP sockets: Sending & Receiving UDP Datagrams with MFC's CAsyncSocket


来源: stackexchange

问:
Full Screen DialogFragment in Android
I'm trying to show an almost fullscreen DialogFragment. But I'm somehow not able to do so.

The way I am showing the Fragment is straight from the android developer documentation

```<code>FragmentManager f = ((Activity)getContext()).getFragmentManager();
FragmentTransaction ft = f.beginTransaction();
Fragment prev = f.findFragmentByTag("dialog");
if (prev != null) {
    ft.remove(prev);
}
ft.addToBackStack(null);

// Create and show the dialog.
DialogFragment newFragment = new DetailsDialogFragment();
newFragment.show(ft, "dialog");
</code>```

I know naively tried to set the RelativeLayout in the fragment to fill_parent and some minWidth and minHeight.

```<code><RelativeLayout
    xmlns:android="http://schemas.android.com/apk/res/android"
    android:layout_width="fill_parent"
    android:layout_height="fill_parent"
    android:minWidth="1000px"
    android:minHeight="600px"
    android:background="#ff0000">
</code>```

I would know expect the DialogFragment to fill the majority of the screen. But I only seems to resize vertically but only until some fixed width horizontally.

I also tried to set the Window Attributes in code, as suggested here: http://groups.google.com/group/android-developers/browse_thread/thread/f0bb813f643604ec. But this didn't help either.

I am probably misunderstanding something about how Android handles Dialogs, as I am brand new to it. How can I do something like this? Are there any alternative ways to reach my goal?

Android Device:

Asus EeePad Transformer

Android 3.0.1

Update:
I now managed to get it into full screen, with the following code in the fragment

```<code>@Override
public void onCreate(Bundle savedInstanceState) {
    super.onCreate(savedInstanceState);
    setStyle(STYLE_NO_FRAME, android.R.style.Theme_Holo_Light);
}
</code>```

Unfortunately, this is not quite want I want. I definitely need a small "padding" around the dialog to show the background.

Any ideas how to accomplish that?

答:
And the kotlin version!</p>

```<code>override fun onStart() {
    super.onStart()
    dialog?.let {
        val width = ViewGroup.LayoutParams.MATCH_PARENT
        val height = ViewGroup.LayoutParams.MATCH_PARENT
        it.window?.setLayout(width, height)
    }
}
</code>```

ContentLicense: CC BY-SA 3.0

Title: Full Screen DialogFragment in Android

Body:
I'm trying to show an almost fullscreen DialogFragment. But I'm somehow not able to do so.

The way I am showing the Fragment is straight from the android developer documentation

FragmentManager f = ((Activity)getContext()).getFragmentManager();
FragmentTransaction ft = f.beginTransaction();
Fragment prev = f.findFragmentByTag("dialog");
if (prev != null) {
    ft.remove(prev);
}
ft.addToBackStack(null);

// Create and show the dialog.
DialogFragment newFragment = new DetailsDialogFragment();
newFragment.show(ft, "dialog");

I know naively tried to set the RelativeLayout in the fragment to fill_parent and some minWidth and minHeight.

<RelativeLayout
    xmlns:android="http://schemas.android.com/apk/res/android"
    android:layout_width="fill_parent"
    android:layout_height="fill_parent"
    android:minWidth="1000px"
    android:minHeight="600px"
    android:background="#ff0000">

I would know expect the DialogFragment to fill the majority of the screen. But I only seems to resize vertically but only until some fixed width horizontally.

I also tried to set the Window Attributes in code, as suggested here: http://groups.google.com/group/android-developers/browse_thread/thread/f0bb813f643604ec. But this didn't help either.

I am probably misunderstanding something about how Android handles Dialogs, as I am brand new to it. How can I do something like this? Are there any alternative ways to reach my goal?

Android Device:

Asus EeePad Transformer

Android 3.0.1

Update:
I now managed to get it into full screen, with the following code in the fragment

@Override
public void onCreate(Bundle savedInstanceState) {
    super.onCreate(savedInstanceState);
    setStyle(STYLE_NO_FRAME, android.R.style.Theme_Holo_Light);
}

Unfortunately, this is not quite want I want. I definitely need a small "padding" around the dialog to show the background.

Any ideas how to accomplish that?

Body:
And the kotlin version!

override fun onStart() {
    super.onStart()
    dialog?.let {
        val width = ViewGroup.LayoutParams.MATCH_PARENT
        val height = ViewGroup.LayoutParams.MATCH_PARENT
        it.window?.setLayout(width, height)
    }
}

ContentLicense: CC BY-SA 4.0


问:
How to if check data in real-time-db FIREBASE
I would like to check/compare if a value is inside this data:

example:

```<code>const uid = '35nv594aotgcv'

#check if uid is inside

firebase
 .database()
   .ref('followers/2mvouwB0E0aEN5MnAhOLWaHiu6b2')
     .once("value", snapshot => {
         if (snapshot.exists()) {
            const data = snapshot.val(); // data are the other two uid's in the image above
         }
     });
</code>```

So how can I check if the const uid = '35nv594aotgcv' is inside the snapshot data?

or if I have an Array with uid's like const uids = ['234', '343', '3242', ...]

答:
If I understand you correctly, you're looking for DataSnapshot.hasChild(). With that you can check whether the snapshot has a certain child node.

Something like:

```<code>firebase
 .database()
 .ref('followers/2mvouwB0E0aEN5MnAhOLWaHiu6b2')
 .once("value", snapshot => {
   if (snapshot.hasChild('35nv594aotgcv')) {
     console.log('Yes');
   }
 });
</code>```

Body:
I would like to check/compare if a value is inside this data:

example:

const uid = '35nv594aotgcv'

#check if uid is inside

firebase
 .database()
   .ref('followers/2mvouwB0E0aEN5MnAhOLWaHiu6b2')
     .once("value", snapshot => {
         if (snapshot.exists()) {
            const data = snapshot.val(); // data are the other two uid's in the image above
         }
     });

So how can I check if the const uid = '35nv594aotgcv' is inside the snapshot data?

or if I have an Array with uid's like const uids = ['234', '343', '3242', ...]

Body:
If I understand you correctly, you're looking for DataSnapshot.hasChild(). With that you can check whether the snapshot has a certain child node.

Something like:

firebase
 .database()
 .ref('followers/2mvouwB0E0aEN5MnAhOLWaHiu6b2')
 .once("value", snapshot => {
   if (snapshot.hasChild('35nv594aotgcv')) {
     console.log('Yes');
   }
 });


问:
How can I wait on multiple results, then filter them based on received data?
I have two observables that I would like to wait for the results of both so I can filter the results of one based upon the other. Individually they wor:

```<code>this.allValues$ = this.store.select(selectors.getAllValues)
this.myId$ = this.store.select(selectors.myId)
</code>```

and I can render them to the template with the async pipe

However I would like to make a class property which holds a filtered array. If it were synchronous JS, something like

```<code>this.filteredResults = allValues.filter(value => value.id === myId)
</code>```

ziping will get me the values

```<code>this.filteredResults$ = zip(
  this.store.select(selectors.getAllValues),
  this.store.select(selectors.myId)
)
</code>```

template:
    results: {{ filteredResults$ | async | json }}

But I cannot understand how to filter like I want. I've tried chaining a pipe to the zip:

```<code>.pipe(
   tap((...args) => {
     console.log({ args }) // only one result so no hope of dropping in `map` or `filter` here
   })
)
</code>```

But this has the effect of removing the allValues array from the result set. allValues is vastly larger so presumably taking longer and zip is no longer waiting for everything to emit so I guess pipe isn't the solution, though it seems close.

How can I can I access both these result sets, filter them, and put that result in an observable I can render in the template with filteredResults$ | async | json?

答:
You could use concatMap or switchMap.

```<code>this.filteredResults = this.store.select(selectors.myId).pipe(
  concatMap(myId => {
    return this.store
      .select(selectors.getAllValues)
      .pipe(filter(value => value.id === myId));
  })
);
</code>```

Body:
I have two observables that I would like to wait for the results of both so I can filter the results of one based upon the other. Individually they wor:

this.allValues$ = this.store.select(selectors.getAllValues)
this.myId$ = this.store.select(selectors.myId)

and I can render them to the template with the async pipe

However I would like to make a class property which holds a filtered array. If it were synchronous JS, something like

this.filteredResults = allValues.filter(value => value.id === myId)

ziping will get me the values

this.filteredResults$ = zip(
  this.store.select(selectors.getAllValues),
  this.store.select(selectors.myId)
)

template:
    results: {{ filteredResults$ | async | json }}

But I cannot understand how to filter like I want. I've tried chaining a pipe to the zip:

.pipe(
   tap((...args) => {
     console.log({ args }) // only one result so no hope of dropping in `map` or `filter` here
   })
)

But this has the effect of removing the allValues array from the result set. allValues is vastly larger so presumably taking longer and zip is no longer waiting for everything to emit so I guess pipe isn't the solution, though it seems close.

How can I can I access both these result sets, filter them, and put that result in an observable I can render in the template with filteredResults$ | async | json?

Body:
You could use concatMap or switchMap.

this.filteredResults = this.store.select(selectors.myId).pipe(
  concatMap(myId => {
    return this.store
      .select(selectors.getAllValues)
      .pipe(filter(value => value.id === myId));
  })
);


问:
Sum all the elements java arraylist
If I had: ArrayList<Double> m = new ArrayList<Double>();
with the double values inside, how should I do to add up all the ArrayList elements?

```<code>public double incassoMargherita()
{
 double sum = 0;
 for(int i = 0; i < m.size(); i++)
 {
 }
 return sum;
}
</code>```

as?

答:
Java 8+ version for Integer, Long, Double and Float

```<code>    List<Integer> ints = Arrays.asList(1, 2, 3, 4, 5);
    List<Long> longs = Arrays.asList(1L, 2L, 3L, 4L, 5L);
    List<Double> doubles = Arrays.asList(1.2d, 2.3d, 3.0d, 4.0d, 5.0d);
    List<Float> floats = Arrays.asList(1.3f, 2.2f, 3.0f, 4.0f, 5.0f);

    long intSum = ints.stream()
            .mapToLong(Integer::longValue)
            .sum();

    long longSum = longs.stream()
            .mapToLong(Long::longValue)
            .sum();

    double doublesSum = doubles.stream()
            .mapToDouble(Double::doubleValue)
            .sum();

    double floatsSum = floats.stream()
            .mapToDouble(Float::doubleValue)
            .sum();

    System.out.println(String.format(
            "Integers: %s, Longs: %s, Doubles: %s, Floats: %s",
            intSum, longSum, doublesSum, floatsSum));
</code>```

15, 15, 15.5, 15.5

Title: Sum all the elements java arraylist

Body:
If I had: ArrayList<Double> m = new ArrayList<Double>();
with the double values inside, how should I do to add up all the ArrayList elements?

public double incassoMargherita()
{
 double sum = 0;
 for(int i = 0; i < m.size(); i++)
 {
 }
 return sum;
}

as?

Body:
Java 8+ version for Integer, Long, Double and Float

    List<Integer> ints = Arrays.asList(1, 2, 3, 4, 5);
    List<Long> longs = Arrays.asList(1L, 2L, 3L, 4L, 5L);
    List<Double> doubles = Arrays.asList(1.2d, 2.3d, 3.0d, 4.0d, 5.0d);
    List<Float> floats = Arrays.asList(1.3f, 2.2f, 3.0f, 4.0f, 5.0f);

    long intSum = ints.stream()
            .mapToLong(Integer::longValue)
            .sum();

    long longSum = longs.stream()
            .mapToLong(Long::longValue)
            .sum();

    double doublesSum = doubles.stream()
            .mapToDouble(Double::doubleValue)
            .sum();

    double floatsSum = floats.stream()
            .mapToDouble(Float::doubleValue)
            .sum();

    System.out.println(String.format(
            "Integers: %s, Longs: %s, Doubles: %s, Floats: %s",
            intSum, longSum, doublesSum, floatsSum));

15, 15, 15.5, 15.5


问:
Update SQL Query with populated variables from AJAX functions over multiple PHP Pages
i try to get help with that question.

All in all Q: It doesnt Update my DB entry like this Step by Step Order how i think it could be done.

its a bit difficult to explain, but i try to explain it step by step with minimal and readable Code. I use the original code, its hard to convert it in reproducible Examples.

A.1 Page ma_aktuelle_ReadOut.php
 There is a php Part

```<code> <?php echo "<a href='ma_Testende.php?TestergebnisID=&TestaufstellungID=". $row['TestaufstellungID']."&TesterID=".$row['TesterID']."' title='Test stoppen' data-toggle='tooltip' class='stoppen'>   <span class='glyphicon glyphicon-stop'></span></a>";
?>
</code>```

When i click this link the following javascript function is called and ask me "really stop?"

```<code><script language="JavaScript" type="text/javascript">
$(document).ready(function(){
  $("a.stoppen").click(function(e){
   if(!confirm('Wirklich stoppen?')){
    e.preventDefault();
    $('.alert').show()
    return false;
    }
    return true;
            });
        });
</script>
<style>
 .alert {
  display: none;
    }
</style>
</code>```

When i cklick "yes" it opens the second Page.

A 2 Page ma_Testende.php
On this Page are 2 AJAX JS Functions.
The first Ajax is asking for "Datum" via type:get from the following next page and wait till success (see Page B 3):

```<code><script src="https://ajax.googleapis.com/ajax/libs/jquery/1.12.4/jquery.min.js">

/* function to get Stoptime for Cycle from DB.TesterCycleCount zu erhalten  */
$(document).ready(async function(){
var Datum;
var TesterID = "<?php echo $_GET['TesterID']; ?>"; /* value from TesterID */
await $.ajax({ /* First Ajax function */
            url: 'ma_get-TesterID_Testende.php',
            type: 'get',
            data: {TesterID:TesterID},
            dataType: 'json',
            success:function(response){
                var CID = response['CID'];
                Datum = response['Datum'];
                console.log(response);
            },
             error: function(jqxhtt, status, exception) {
                 console.log(exception);
         alert('Exception:', exception)
            }
        });
console.log();
        var TestaufstellungID = "<?php echo $_GET['TestaufstellungID']; ?>";
         $.ajax({ /* Second Ajax function */
            url: 'ma_TestendeSQL.php',
            type: 'get',
            data: {TestaufstellungID:TestaufstellungID, Datum: Datum},
            dataType: 'json',
            success:function(data){
            alert('Successfully called');
     },
     error: function(jqxhr, status, exception) {
         console.log(exception);
         alert('Exception:', exception)
            }
        });
        });
</script>
</code>```

B 3 Page ma_get-TesterID_Testende.php

```<code><?php
$cinfo = array(
    "Database" => $database,
    "UID" => $username,
    "PWD" => $password
);
$conn = sqlsrv_connect($server, $cinfo);
                $sqlreadZeit = "Select TOP 1 CID,Datum from DB.dbo.TesterCycleCount where TesterID = '".$_GET['TesterID']."' order by Datum DESC";
                $result1 = sqlsrv_query($conn, $sqlreadZeit);
                $zeiten_arr = array();
                while ($row = sqlsrv_fetch_array($result1, SQLSRV_FETCH_ASSOC)) {
                $CID = $row['CID'];
                $Datum = $row['Datum']->format('d.m.Y h:m:s');
                $zeiten_arr[] = array("CID" => $CID, "Datum" => $Datum);
                                }
    header('Content-type: application/json');
  echo json_encode($zeiten_arr);
?>
</code>```

Back with the "Datum" the second AJAX is called (see Page A 2)
With the "Datum" and "TestaufstellungID" as variable it should be call the next Page and Update the DB entry with the populated variablles.

B. 4 Page ma_TestendeSQL.php

```<code><?php
$cinfo = array(
    "Database" => $database,
    "UID" => $username,
    "PWD" => $password
);
$conn = sqlsrv_connect($server, $cinfo);

$TestaufstellungID = $_GET['TestaufstellungID'];
$Testende= $_GET['Datum'];
$Testdatum = date('Y-d-m');

$stop = $connection->prepare("WITH UpdateTestende AS (
  SELECT TOP 1  * from DB.dbo.Testergebnisse
  WHERE TestaufstellungID = :TestaufstellungID
  ORDER BY TestergebnisID DESC
)
update UpdateTestende
set Testende = :Testende,
Datum = :Testdatum");
$stop->execute(array(':TestaufstellungID' => $TestaufstellungID, ':Testdatum' => $Testdatum, ':Testende' => $Testende));

    header('Content-type: application/json');
?>
</code>```

The php variable $Testende get the populated "Datum" from the Ajax functions. All in all at the end it should be Update, when i click on the link the ( Page A 1) my DB entry with the populated "Datum" which i get from the first Ajax call ( Page A 2 ) from the SQL Query ( Page B 3) back to the second AJAX Call ( Page A 2 )  than with the data: {TestaufstellungID:TestaufstellungID, Datum: Datum}  to the last page ( Page B 4)

But it doesnt Update my DB entry like this Step by Step Order how i think it could be done.

Encapsulated is the SQL-Code working fine. With the Code header('Content-type: application/json'); the browser tell me the following when i click on the link from ( Page A 1 )

SyntaxError: JSON.parse: unexpected character at line 1 column 1 of the JSON data

Thats why i posted all the Step i think on one point the variables are not passed right to the next page or they are empty becasue the code is not executed in the right order Server/Client PHP/JS or Asynchronous problem...
The console.log tell me nothing. At the moment i have no idea where to start with the debugging?

Hope someone can help me. thx

Edit: iam pretty sure the ajax call is empty, but i dont see it in which step the values getting empty

Edit2:
AJAX Call is empty or is not starting.
Further invstigation:  The Ajax alert me the error part with empty exception and dont alert me the success part. So it doesnt  go to the page ma_get-TesterID_Testende.php or it doesnt  return back the Datum .
Could be not enabled Cross-Site-Scripting be the Problem?

But in another Page is a similiar Ajax Call working fine.

```<code>$(document).ready(function(){

var TesterID = "<?php echo $_GET['TesterID']; ?>"; /* value der Tester erhalten */

        $.ajax({ /* AJAX aufrufen */
            url: 'ma_get-TesterID.php',
            type: 'get', /* Methode zum übertragen der Daten */
            data: {TesterID:TesterID}, /* Daten zu übermitteln */
            dataType: 'json',
            success:function(response){ /* Die zurückgegebenene Daten erhalten */

                var len = response.length;

                $("#Teststart").empty(); /* Die erhaltenden Daten werden bei der ID angezeigt */
                for( var i = 0; i<len; i++){
                    var CID = response[i]['CID'];
                    var Datum = response[i]['Datum'];

                    $("#Teststart").append("<option value='"+Datum+"'>"+Datum+"</option>");

                }
            }
        });

    $("#TesterID").change(function(){ /* Wenn du änderst und vom Select Feld auswählst */
        var TesterID = $(this).val(); /* value der Tester erhalten */

        $.ajax({ /* AJAX aufrufen */
            url: 'ma_get-TesterID.php',
            type: 'get', /* Methode zum übertragen der Daten */
            data: {TesterID:TesterID}, /* Daten zu übermitteln */
            dataType: 'json',
            success:function(response){ /* Die zurückgegebenene Daten erhalten */

                var len = response.length;

                $("#Teststart").empty(); /* Die erhaltenden Daten werden bei der ID angezeigt */
                for( var i = 0; i<len; i++){
                    var CID = response[i]['CID'];
                    var Datum = response[i]['Datum'];

                    $("#Teststart").append("<option value='"+Datum+"'>"+Datum+"</option>");

                }
            }
        });
    });

});
</code>```

In this example the Ajax Call starts when i change the value from a Dropdown selection Form.    Is there a difference?

How this Ajax should work i try to explain in my other question step by step, how it my application should be execute.

Update SQL Query with populated variables from AJAX functions over multiple PHP Pages

Edit 3:
JQuery Version:
https://code.jquery.com/jquery-3.4.1.js

答:
One alternative is use $_SESSION superglobal; I offer it as this question is tagged as PHP rather than AJAX/JSON, and to avoid encode-decode common issues with JSON values or arrays. If you're able to, change your strategy and use client-side to broadcast data and stop normal flow in an error response event.

With a started session_start() you can use an inner temporary array in $_SESSION to attach/detach step by step data, in this example "step" array, like this:

```<code><?php
// step 1
$_SESSION['step'][1]['TesterID']            = 64;
$_SESSION['step'][1]['var2']                = 'bar';
// step 2
$_SESSION['step'][2]['TestaufstellungID']   = 65;
$_SESSION['step'][2]['var4']                = 100;
$_SESSION['step'][2]['var5']                = 256.04;
?>
</code>```

When you send data, over AJAX, is not necesarry to convert it to JSON, because you can work with $_POST object. Meanwhile, response can give to you every $_SESSION['step'] values in JSON format.

```<code><?php
header("Content-type:application/json")
// conditions goes here
if ( $conditions == true ) {
    echo json_encode($_SESSION['step']);
}
?>
</code>```

This way, and considering is a "step by step" process, you can chose to save an json_encode() object updating in every step, or use session superglobal to save it only when process finish, considering all "step" array or just relevant values, users id in this case

https://www.php.net/manual/es/reserved.variables.session.php

https://www.php.net/manual/es/function.session-id.php

https://www.php.net/manual/es/function.json-encode.php

Body:
i try to get help with that question.

All in all Q: It doesnt Update my DB entry like this Step by Step Order how i think it could be done.

its a bit difficult to explain, but i try to explain it step by step with minimal and readable Code. I use the original code, its hard to convert it in reproducible Examples.

A.1 Page ma_aktuelle_ReadOut.php
 There is a php Part

 <?php echo "   ";
?>

When i click this link the following javascript function is called and ask me "really stop?"

When i cklick "yes" it opens the second Page.

A 2 Page ma_Testende.php
On this Page are 2 AJAX JS Functions.
The first Ajax is asking for "Datum" via type:get from the following next page and wait till success (see Page B 3):

B 3 Page ma_get-TesterID_Testende.php

<?php
$cinfo = array(
    "Database" => $database,
    "UID" => $username,
    "PWD" => $password
);
$conn = sqlsrv_connect($server, $cinfo);
                $sqlreadZeit = "Select TOP 1 CID,Datum from DB.dbo.TesterCycleCount where TesterID = '".$_GET['TesterID']."' order by Datum DESC";
                $result1 = sqlsrv_query($conn, $sqlreadZeit);
                $zeiten_arr = array();
                while ($row = sqlsrv_fetch_array($result1, SQLSRV_FETCH_ASSOC)) {
                $CID = $row['CID'];
                $Datum = $row['Datum']->format('d.m.Y h:m:s');
                $zeiten_arr[] = array("CID" => $CID, "Datum" => $Datum);
                                }
    header('Content-type: application/json');
  echo json_encode($zeiten_arr);
?>

Back with the "Datum" the second AJAX is called (see Page A 2)
With the "Datum" and "TestaufstellungID" as variable it should be call the next Page and Update the DB entry with the populated variablles.

B. 4 Page ma_TestendeSQL.php

<?php
$cinfo = array(
    "Database" => $database,
    "UID" => $username,
    "PWD" => $password
);
$conn = sqlsrv_connect($server, $cinfo);

$TestaufstellungID = $_GET['TestaufstellungID'];
$Testende= $_GET['Datum'];
$Testdatum = date('Y-d-m');

$stop = $connection->prepare("WITH UpdateTestende AS (
  SELECT TOP 1  * from DB.dbo.Testergebnisse
  WHERE TestaufstellungID = :TestaufstellungID
  ORDER BY TestergebnisID DESC
)
update UpdateTestende
set Testende = :Testende,
Datum = :Testdatum");
$stop->execute(array(':TestaufstellungID' => $TestaufstellungID, ':Testdatum' => $Testdatum, ':Testende' => $Testende));

    header('Content-type: application/json');
?>

The php variable $Testende get the populated "Datum" from the Ajax functions. All in all at the end it should be Update, when i click on the link the ( Page A 1) my DB entry with the populated "Datum" which i get from the first Ajax call ( Page A 2 ) from the SQL Query ( Page B 3) back to the second AJAX Call ( Page A 2 )  than with the data: {TestaufstellungID:TestaufstellungID, Datum: Datum}  to the last page ( Page B 4)

But it doesnt Update my DB entry like this Step by Step Order how i think it could be done.

Encapsulated is the SQL-Code working fine. With the Code header('Content-type: application/json'); the browser tell me the following when i click on the link from ( Page A 1 )

SyntaxError: JSON.parse: unexpected character at line 1 column 1 of the JSON data

Thats why i posted all the Step i think on one point the variables are not passed right to the next page or they are empty becasue the code is not executed in the right order Server/Client PHP/JS or Asynchronous problem...
The console.log tell me nothing. At the moment i have no idea where to start with the debugging?

Hope someone can help me. thx

Edit: iam pretty sure the ajax call is empty, but i dont see it in which step the values getting empty

Edit2:
AJAX Call is empty or is not starting.
Further invstigation:  The Ajax alert me the error part with empty exception and dont alert me the success part. So it doesnt  go to the page ma_get-TesterID_Testende.php or it doesnt  return back the Datum .
Could be not enabled Cross-Site-Scripting be the Problem?

But in another Page is a similiar Ajax Call working fine.

$(document).ready(function(){

var TesterID = "<?php echo $_GET['TesterID']; ?>"; /* value der Tester erhalten */

        $.ajax({ /* AJAX aufrufen */
            url: 'ma_get-TesterID.php',
            type: 'get', /* Methode zum übertragen der Daten */
            data: {TesterID:TesterID}, /* Daten zu übermitteln */
            dataType: 'json',
            success:function(response){ /* Die zurückgegebenene Daten erhalten */

                var len = response.length;

                $("#Teststart").empty(); /* Die erhaltenden Daten werden bei der ID angezeigt */
                for( var i = 0; i<len; i++){
                    var CID = response[i]['CID'];
                    var Datum = response[i]['Datum'];

                    $("#Teststart").append("<option value='"+Datum+"'>"+Datum+"</option>");

                }
            }
        });

    $("#TesterID").change(function(){ /* Wenn du änderst und vom Select Feld auswählst */
        var TesterID = $(this).val(); /* value der Tester erhalten */

        $.ajax({ /* AJAX aufrufen */
            url: 'ma_get-TesterID.php',
            type: 'get', /* Methode zum übertragen der Daten */
            data: {TesterID:TesterID}, /* Daten zu übermitteln */
            dataType: 'json',
            success:function(response){ /* Die zurückgegebenene Daten erhalten */

                var len = response.length;

                $("#Teststart").empty(); /* Die erhaltenden Daten werden bei der ID angezeigt */
                for( var i = 0; i<len; i++){
                    var CID = response[i]['CID'];
                    var Datum = response[i]['Datum'];

                    $("#Teststart").append("<option value='"+Datum+"'>"+Datum+"</option>");

                }
            }
        });
    });

});

In this example the Ajax Call starts when i change the value from a Dropdown selection Form.    Is there a difference?

How this Ajax should work i try to explain in my other question step by step, how it my application should be execute.

Update SQL Query with populated variables from AJAX functions over multiple PHP Pages

Edit 3:
JQuery Version:
https://code.jquery.com/jquery-3.4.1.js

Body:
One alternative is use $_SESSION superglobal; I offer it as this question is tagged as PHP rather than AJAX/JSON, and to avoid encode-decode common issues with JSON values or arrays. If you're able to, change your strategy and use client-side to broadcast data and stop normal flow in an error response event.

With a started session_start() you can use an inner temporary array in $_SESSION to attach/detach step by step data, in this example "step" array, like this:

<?php
// step 1
$_SESSION['step'][1]['TesterID']            = 64;
$_SESSION['step'][1]['var2']                = 'bar';
// step 2
$_SESSION['step'][2]['TestaufstellungID']   = 65;
$_SESSION['step'][2]['var4']                = 100;
$_SESSION['step'][2]['var5']                = 256.04;
?>

When you send data, over AJAX, is not necesarry to convert it to JSON, because you can work with $_POST object. Meanwhile, response can give to you every $_SESSION['step'] values in JSON format.

<?php
header("Content-type:application/json")
// conditions goes here
if ( $conditions == true ) {
    echo json_encode($_SESSION['step']);
}
?>

This way, and considering is a "step by step" process, you can chose to save an json_encode() object updating in every step, or use session superglobal to save it only when process finish, considering all "step" array or just relevant values, users id in this case

https://www.php.net/manual/es/reserved.variables.session.php

https://www.php.net/manual/es/function.session-id.php

https://www.php.net/manual/es/function.json-encode.php


问:
WinSCP .NET assembly in PowerShell fails to authenticate with password, while WinSCP GUI works
I am trying to automate the transfer of a file via SFTP using PowerShell.  The SFTP connection requires public/private key and username/password.  I am using WinSCP to do the transfer in PowerShell.  After the authentication via the keys it fails right afterwards.  It seems to have to do with Interactive mode being required.  If I was using FileZilla to manually do this I have to do it in Interactive mode and type the password in after the keys are exchanged to get connected.

```<code>Add-Type -Path "WinSCPnet.dll"

$sessionOptions = New-Object WinSCP.SessionOptions -Property @{
    Protocol = [WinSCP.Protocol]::Sftp
    HostName = "stage.sample.com"
    PortNumber= 22
    UserName = "MyUsername"
    Password = "MyPassword"
    SshHostKeyFingerprint = "ssh-rsa 1024 znVXTS2xndXS4dKADWyRUUzImR/kG1Ipojlr2eL2765="
    SshPrivateKeyPath="D:\PrivateKeys\private.ppk"
    PrivateKeyPassphrase="MyPrivateKeypassword"
}

$session = New-Object WinSCP.Session

try
{
    # Connect
    $session.Open($sessionOptions)
    # Your code
    $session.PutFiles("d:\6201_2019-04-15.zip", "\6201_2019-04-15.zip")
}
finally
{
    $session.Dispose()
}
</code>```

WinSCP Log when using the UI and it works:

. 2019-05-28 09:35:25.692 --------------------------------------------------------------------------
. 2019-05-28 09:35:25.692 WinSCP Version 5.15.1 (Build 9407) (OS 6.1.7601 Service Pack 1 - Windows Server 2008 R2 Standard)
. 2019-05-28 09:35:25.692 Configuration: D:\Ei Dynamics\sftp\WinSCP.ini
. 2019-05-28 09:35:25.693 Log level: Normal
. 2019-05-28 09:35:25.693 Local account: B\a_xyz
. 2019-05-28 09:35:25.693 Working directory: D:\Ei Dynamics\sftp
. 2019-05-28 09:35:25.693 Process ID: 11292
. 2019-05-28 09:35:25.693 Command-line: "D:\Ei Dynamics\sftp\WinSCP.exe"
. 2019-05-28 09:35:25.694 Time zone: Current: GMT-5, Standard: GMT-6 (Central Standard Time), DST: GMT-5 (Central Daylight Time), DST Start: 3/10/2019, DST End: 11/3/2019
. 2019-05-28 09:35:25.694 Login time: Tuesday, May 28, 2019 9:35:25 AM
. 2019-05-28 09:35:25.694 --------------------------------------------------------------------------
. 2019-05-28 09:35:25.694 Session name: MyUsername@stage.example.com (Modified site)
. 2019-05-28 09:35:25.694 Host name: stage.example.com (Port: 10022)
. 2019-05-28 09:35:25.694 User name: MyUsername (Password: Yes, Key file: Yes, Passphrase: No)
. 2019-05-28 09:35:25.694 Tunnel: No
. 2019-05-28 09:35:25.694 Transfer Protocol: SFTP (SCP)
. 2019-05-28 09:35:25.694 Ping type: Off, Ping interval: 30 sec; Timeout: 15 sec
. 2019-05-28 09:35:25.694 Disable Nagle: No
. 2019-05-28 09:35:25.694 Proxy: None
. 2019-05-28 09:35:25.694 Send buffer: 262144
. 2019-05-28 09:35:25.694 SSH protocol version: 2; Compression: No
. 2019-05-28 09:35:25.694 Bypass authentication: No
. 2019-05-28 09:35:25.694 Try agent: Yes; Agent forwarding: No; TIS/CryptoCard: No; KI: Yes; GSSAPI: Yes
. 2019-05-28 09:35:25.694 GSSAPI: Forwarding: No; Libs: gssapi32,sspi,custom; Custom:
. 2019-05-28 09:35:25.694 Ciphers: aes,chacha20,blowfish,3des,WARN,arcfour,des; Ssh2DES: No
. 2019-05-28 09:35:25.694 KEX: ecdh,dh-gex-sha1,dh-group14-sha1,rsa,WARN,dh-group1-sha1
. 2019-05-28 09:35:25.694 SSH Bugs: Auto,Auto,Auto,Auto,Auto,Auto,Auto,Auto,Auto,Auto,Auto,Auto,Auto
. 2019-05-28 09:35:25.694 Simple channel: Yes
. 2019-05-28 09:35:25.694 Return code variable: Autodetect; Lookup user groups: Auto
. 2019-05-28 09:35:25.694 Shell: default
. 2019-05-28 09:35:25.694 EOL: LF, UTF: Auto
. 2019-05-28 09:35:25.694 Clear aliases: Yes, Unset nat.vars: Yes, Resolve symlinks: Yes; Follow directory symlinks: No
. 2019-05-28 09:35:25.694 LS: ls -la, Ign LS warn: Yes, Scp1 Comp: No; Exit code 1 is error: No
. 2019-05-28 09:35:25.694 SFTP Bugs: Auto,Auto
. 2019-05-28 09:35:25.694 SFTP Server: default
. 2019-05-28 09:35:25.694 Local directory: default, Remote directory: home, Update: Yes, Cache: Yes
. 2019-05-28 09:35:25.694 Cache directory changes: Yes, Permanent: Yes
. 2019-05-28 09:35:25.694 Recycle bin: Delete to: No, Overwritten to: No, Bin path:
. 2019-05-28 09:35:25.694 DST mode: Unix
. 2019-05-28 09:35:25.694 --------------------------------------------------------------------------
. 2019-05-28 09:35:25.723 Looking up host "stage.example.com" for SSH connection
. 2019-05-28 09:35:25.724 Connecting to 192.123.100.123 port 10022
. 2019-05-28 09:35:25.747 We claim version: SSH-2.0-WinSCP_release_5.15.1
. 2019-05-28 09:35:25.778 Server version: SSH-2.0-Maverick_SSHD
. 2019-05-28 09:35:25.778 Using SSH protocol version 2
. 2019-05-28 09:35:25.783 Have a known host key of type rsa2
. 2019-05-28 09:35:25.785 Doing Diffie-Hellman group exchange
. 2019-05-28 09:35:25.875 Doing Diffie-Hellman key exchange with hash SHA-1
. 2019-05-28 09:35:26.106 Host key fingerprint is:
. 2019-05-28 09:35:26.106 ssh-rsa 1024 e6:c8:78:79:f9:d4:e9:af:f2:53:28:6d:87:c8:62:f5 znVXTS2xndXS4dKADWyRUUzImR/kG1Ipojlr2eL1234=
. 2019-05-28 09:35:26.111 Host key matches cached key
. 2019-05-28 09:35:26.113 Initialised AES-256 CBC client->server encryption
. 2019-05-28 09:35:26.113 Initialised HMAC-SHA1 client->server MAC algorithm
. 2019-05-28 09:35:26.113 Initialised AES-256 CBC server->client encryption
. 2019-05-28 09:35:26.113 Initialised HMAC-SHA1 server->client MAC algorithm
. 2019-05-28 09:35:26.196 Reading key file "D:\privateKeys\myprivate.ppk"
! 2019-05-28 09:35:26.196 Using username "MyUsername".
. 2019-05-28 09:35:31.197 Server offered these authentication methods: password,publickey,keyboard-interactive
. 2019-05-28 09:35:31.197 Offered public key
. 2019-05-28 09:35:31.247 Offer of public key accepted
! 2019-05-28 09:35:31.247 Authenticating with public key "rsa-key-20190313"
. 2019-05-28 09:35:31.262 Prompt (passphrase, "SSH key passphrase", <no instructions>, "Passphrase for key "rsa-key-20190313": ")
. 2019-05-28 09:35:33.837 Sent public key signature
! 2019-05-28 09:35:33.864 Further authentication required
. 2019-05-28 09:35:33.869 Further authentication required
. 2019-05-28 09:35:33.869 Server offered these authentication methods: password,keyboard-interactive8ƒÆqtY"Ç4¡FØwFÎ±[D*ó6çeÊNô§1‚>°
. 2019-05-28 09:35:33.869 Attempting keyboard-interactive authentication
. 2019-05-28 09:35:33.895 Prompt (keyboard interactive, "SSH server: password", "Using keyboard-interactive authentication.
. 2019-05-28 09:35:33.895 Enter Password for MyUsername:", "Password:")
. 2019-05-28 09:35:33.895 Using stored password.
. 2019-05-28 09:35:33.958 Access granted
. 2019-05-28 09:35:33.958 Opening session as main channel
. 2019-05-28 09:35:33.982 Opened main channel
. 2019-05-28 09:35:34.149 Started a shell/command
. 2019-05-28 09:35:34.157 --------------------------------------------------------------------------
. 2019-05-28 09:35:34.158 Using SFTP protocol.
. 2019-05-28 09:35:34.160 Doing startup conversation with host.
> 2019-05-28 09:35:34.170 Type: SSH_FXP_INIT, Size: 5, Number: -1
< 2019-05-28 09:35:34.193 Type: SSH_FXP_VERSION, Size: 33, Number: -1
. 2019-05-28 09:35:34.193 SFTP version 3 negotiated.
. 2019-05-28 09:35:34.193 Unknown server extension newline@vandyke.com="\n"
. 2019-05-28 09:35:34.193 We believe the server has signed timestamps bug
. 2019-05-28 09:35:34.193 We will use UTF-8 strings until server sends an invalid UTF-8 string as with SFTP version 3 and older UTF-8 strings are not mandatory
. 2019-05-28 09:35:34.193 Getting current directory name.
. 2019-05-28 09:35:34.193 Getting real path for '.'
> 2019-05-28 09:35:34.193 Type: SSH_FXP_REALPATH, Size: 10, Number: 2832
< 2019-05-28 09:35:34.226 Type: SSH_FXP_NAME, Size: 51, Number: 2832
. 2019-05-28 09:35:34.226 Real path is '/'
. 2019-05-28 09:35:34.267 Listing directory "/".
> 2019-05-28 09:35:34.267 Type: SSH_FXP_OPENDIR, Size: 10, Number: 3083
< 2019-05-28 09:35:34.296 Type: SSH_FXP_HANDLE, Size: 10, Number: 3083
> 2019-05-28 09:35:34.296 Type: SSH_FXP_READDIR, Size: 10, Number: 3340
< 2019-05-28 09:35:34.394 Type: SSH_FXP_NAME, Size: 112, Number: 3340
> 2019-05-28 09:35:34.394 Type: SSH_FXP_READDIR, Size: 10, Number: 3596
< 2019-05-28 09:35:34.426 Type: SSH_FXP_STATUS, Size: 45, Number: 3596
< 2019-05-28 09:35:34.426 Status code: 1
> 2019-05-28 09:35:34.426 Type: SSH_FXP_CLOSE, Size: 10, Number: 3844
. 2019-05-28 09:35:34.426 3098;d;0;2019-05-28T14:35:34.000Z;3;"300" [300];"100" [100];rwx------;0
. 2019-05-28 09:35:34.426 ..;D;0;1899-12-30T06:00:00.000Z;0;"" [0];"" [0];---------;0
. 2019-05-28 09:35:34.482 Startup conversation with host finished.
. 2019-05-28 09:35:50.983 Received disconnect message (by application)
. 2019-05-28 09:35:50.983 Disconnection message text: Idle connection
. 2019-05-28 09:35:50.983 Server sent disconnect message
. 2019-05-28 09:35:50.983 type 11 (by application):
. 2019-05-28 09:35:50.983 "Idle connection"
. 2019-05-28 09:38:36.501 Received disconnect message (by application)
. 2019-05-28 09:38:36.501 Disconnection message text: Idle connection
. 2019-05-28 09:38:36.501 Server sent disconnect message
. 2019-05-28 09:38:36.501 type 11 (by application):
. 2019-05-28 09:38:36.501 "Idle connection"
* 2019-05-28 09:38:36.501 (ESshFatal) Server sent disconnect message
* 2019-05-28 09:38:36.501 type 11 (by application):
* 2019-05-28 09:38:36.501 "Idle connection"
. 2019-05-28 09:38:45.572 Looking up host "stage.example.com" for SSH connection
. 2019-05-28 09:38:45.573 Connecting to 192.123.100.123 port 10022
. 2019-05-28 09:38:45.595 We claim version: SSH-2.0-WinSCP_release_5.15.1
. 2019-05-28 09:38:45.619 Server version: SSH-2.0-Maverick_SSHD
. 2019-05-28 09:38:45.619 Using SSH protocol version 2
. 2019-05-28 09:38:45.621 Have a known host key of type rsa2
. 2019-05-28 09:38:45.622 Doing Diffie-Hellman group exchange
. 2019-05-28 09:38:45.717 Doing Diffie-Hellman key exchange with hash SHA-1
. 2019-05-28 09:38:45.865 Host key fingerprint is:
. 2019-05-28 09:38:45.865 ssh-rsa 1024 e6:c8:78:79:f9:d4:e9:af:f2:53:28:6d:87:c8:62:f5 znVXTS2xndXS4dKADWyRUUzImR/kG1Ipojlr2e1234=
. 2019-05-28 09:38:45.910 Host key matches cached key
. 2019-05-28 09:38:45.911 Initialised AES-256 CBC client->server encryption
. 2019-05-28 09:38:45.911 Initialised HMAC-SHA1 client->server MAC algorithm
. 2019-05-28 09:38:45.911 Initialised AES-256 CBC server->client encryption
. 2019-05-28 09:38:45.911 Initialised HMAC-SHA1 server->client MAC algorithm
. 2019-05-28 09:38:45.996 Reading key file "D:\privateKeys\myprivate.ppk"
! 2019-05-28 09:38:45.996 Using username "MyUsername".
. 2019-05-28 09:39:19.037 Received disconnect message (by application)
. 2019-05-28 09:39:19.037 Disconnection message text: Idle connection
. 2019-05-28 09:39:19.037 Server sent disconnect message
. 2019-05-28 09:39:19.037 type 11 (by application):
. 2019-05-28 09:39:19.037 "Idle connection"
```

<p>Powershell Log file</p>

<pre class="lang-none prettyprint-override"><code>. 2019-05-28 09:37:41.686 --------------------------------------------------------------------------
. 2019-05-28 09:37:41.686 WinSCP Version 5.15.1 (Build 9407) (OS 6.1.7601 Service Pack 1 - Windows Server 2008 R2 Standard)
. 2019-05-28 09:37:41.686 Configuration: nul
. 2019-05-28 09:37:41.686 Log level: Normal
. 2019-05-28 09:37:41.686 Local account: B\a_xyz
. 2019-05-28 09:37:41.686 Working directory: D:\Ei Dynamics\sftp
. 2019-05-28 09:37:41.686 Process ID: 132
. 2019-05-28 09:37:41.687 Command-line: "D:\Ei Dynamics\sftp\winscp.exe" /xmllog="C:\Users\a_xyz\AppData\Local\Temp\13\wscp2EA0.01871C8A.tmp" /xmlgroups /xmllogrequired /nointeractiveinput /dotnet=5.15.1  /ini=nul /log="D:\Ei Dynamics\sftp\powershell.log"  /console /consoleinstance=_11936_48002702_723
. 2019-05-28 09:37:41.687 Time zone: Current: GMT-5, Standard: GMT-6 (Central Standard Time), DST: GMT-5 (Central Daylight Time), DST Start: 3/10/2019, DST End: 11/3/2019
. 2019-05-28 09:37:41.687 Login time: Tuesday, May 28, 2019 9:37:41 AM
. 2019-05-28 09:37:41.687 --------------------------------------------------------------------------
. 2019-05-28 09:37:41.687 Script: Retrospectively logging previous script records:
> 2019-05-28 09:37:41.687 Script: option batch on
< 2019-05-28 09:37:41.687 Script: batch           on
< 2019-05-28 09:37:41.687 Script: reconnecttime   120
> 2019-05-28 09:37:41.687 Script: option confirm off
< 2019-05-28 09:37:41.687 Script: confirm         off
> 2019-05-28 09:37:41.687 Script: option reconnecttime 120
< 2019-05-28 09:37:41.687 Script: reconnecttime   120
> 2019-05-28 09:37:41.687 Script: open sftp://MyUsername:***@stage.example.com:10022 -hostkey="ssh-rsa 1024 znVXTS2xndXS4dKADWyRUUzImR/kG1Ipojlr2eL1234=" -privatekey="D:\PrivateKeys\myprivate.ppk" -timeout=15 -passphrase=***
. 2019-05-28 09:37:41.687 --------------------------------------------------------------------------
. 2019-05-28 09:37:41.687 Session name: MyUsername@stage.example.com (Ad-Hoc site)
. 2019-05-28 09:37:41.687 Host name: stage.example.com (Port: 10022)
. 2019-05-28 09:37:41.688 User name: MyUsername (Password: Yes, Key file: Yes, Passphrase: Yes)
. 2019-05-28 09:37:41.688 Tunnel: No
. 2019-05-28 09:37:41.688 Transfer Protocol: SFTP
. 2019-05-28 09:37:41.688 Ping type: Off, Ping interval: 30 sec; Timeout: 15 sec
. 2019-05-28 09:37:41.688 Disable Nagle: No
. 2019-05-28 09:37:41.688 Proxy: None
. 2019-05-28 09:37:41.688 Send buffer: 262144
. 2019-05-28 09:37:41.688 SSH protocol version: 2; Compression: No
. 2019-05-28 09:37:41.688 Bypass authentication: No
. 2019-05-28 09:37:41.688 Try agent: Yes; Agent forwarding: No; TIS/CryptoCard: No; KI: Yes; GSSAPI: Yes
. 2019-05-28 09:37:41.688 GSSAPI: Forwarding: No; Libs: gssapi32,sspi,custom; Custom:
. 2019-05-28 09:37:41.688 Ciphers: aes,chacha20,blowfish,3des,WARN,arcfour,des; Ssh2DES: No
. 2019-05-28 09:37:41.688 KEX: ecdh,dh-gex-sha1,dh-group14-sha1,rsa,WARN,dh-group1-sha1
. 2019-05-28 09:37:41.688 SSH Bugs: Auto,Auto,Auto,Auto,Auto,Auto,Auto,Auto,Auto,Auto,Auto,Auto,Auto
. 2019-05-28 09:37:41.688 Simple channel: Yes
. 2019-05-28 09:37:41.688 Return code variable: Autodetect; Lookup user groups: Auto
. 2019-05-28 09:37:41.688 Shell: default
. 2019-05-28 09:37:41.688 EOL: LF, UTF: Auto
. 2019-05-28 09:37:41.688 Clear aliases: Yes, Unset nat.vars: Yes, Resolve symlinks: Yes; Follow directory symlinks: No
. 2019-05-28 09:37:41.688 LS: ls -la, Ign LS warn: Yes, Scp1 Comp: No; Exit code 1 is error: No
. 2019-05-28 09:37:41.688 SFTP Bugs: Auto,Auto
. 2019-05-28 09:37:41.688 SFTP Server: default
. 2019-05-28 09:37:41.688 Local directory: default, Remote directory: home, Update: Yes, Cache: Yes
. 2019-05-28 09:37:41.688 Cache directory changes: Yes, Permanent: Yes
. 2019-05-28 09:37:41.688 Recycle bin: Delete to: No, Overwritten to: No, Bin path:
. 2019-05-28 09:37:41.688 DST mode: Unix
. 2019-05-28 09:37:41.688 --------------------------------------------------------------------------
. 2019-05-28 09:37:41.689 Looking up host "stage.example.com" for SSH connection
. 2019-05-28 09:37:41.736 Connecting to 192.123.100.123 port 10022
. 2019-05-28 09:37:41.757 We claim version: SSH-2.0-WinSCP_release_5.15.1
. 2019-05-28 09:37:41.782 Server version: SSH-2.0-Maverick_SSHD
. 2019-05-28 09:37:41.782 Using SSH protocol version 2
. 2019-05-28 09:37:41.782 Have a known host key of type rsa2
. 2019-05-28 09:37:41.782 Doing Diffie-Hellman group exchange
. 2019-05-28 09:37:41.872 Doing Diffie-Hellman key exchange with hash SHA-1
. 2019-05-28 09:37:42.039 Host key fingerprint is:
. 2019-05-28 09:37:42.039 ssh-rsa 1024 e6:c8:78:79:f9:d4:e9:af:f2:53:28:6d:87:c8:62:f5 znVXTS2xndXS4dKADWyRUUzImR/kG1Ipojlr2eL1234=
. 2019-05-28 09:37:42.040 Host key matches configured key
. 2019-05-28 09:37:42.040 Initialised AES-256 CBC client->server encryption
. 2019-05-28 09:37:42.040 Initialised HMAC-SHA1 client->server MAC algorithm
. 2019-05-28 09:37:42.040 Initialised AES-256 CBC server->client encryption
. 2019-05-28 09:37:42.040 Initialised HMAC-SHA1 server->client MAC algorithm
. 2019-05-28 09:37:42.125 Reading key file "D:\PrivateKeys\myprivate.ppk"
! 2019-05-28 09:37:42.126 Using username "MyUsername".
. 2019-05-28 09:37:42.149 Server offered these authentication methods: password,publickey,keyboard-interactive
. 2019-05-28 09:37:42.149 Offered public key
. 2019-05-28 09:37:42.201 Offer of public key accepted
! 2019-05-28 09:37:42.201 Authenticating with public key "rsa-key-20190313"
. 2019-05-28 09:37:42.202 Prompt (passphrase, "SSH key passphrase", <no instructions>, "Passphrase for key "rsa-key-20190313": ")
. 2019-05-28 09:37:42.202 Using configured passphrase.
. 2019-05-28 09:37:42.330 Sent public key signature
! 2019-05-28 09:37:42.354 Further authentication required
. 2019-05-28 09:37:42.355 Further authentication required
. 2019-05-28 09:37:42.355 Server offered these authentication methods: password,keyboard-interactive}®”Çÿ®UÆ'Éî€ûw‘BÊMNŽoKÓU/W
. 2019-05-28 09:37:42.355 Attempting keyboard-interactive authentication
. 2019-05-28 09:37:42.377 Prompt (keyboard interactive, "SSH server: password", "Using keyboard-interactive authentication.
. 2019-05-28 09:37:42.377 Enter Password for MyUsername:", "Password:")
. 2019-05-28 09:37:42.377 Using stored password.
. 2019-05-28 09:37:42.432 Keyboard-interactive authentication failed
! 2019-05-28 09:37:42.432 Access denied
. 2019-05-28 09:37:42.436 Server offered these authentication methods: password,keyboard-interactive
. 2019-05-28 09:37:42.436 Attempting keyboard-interactive authentication
. 2019-05-28 09:37:42.458 Prompt (keyboard interactive, "SSH server: password", "Using keyboard-interactive authentication.
. 2019-05-28 09:37:42.458 Invalid Password, reenter Password for MyUsername:", "Password:")
. 2019-05-28 09:37:42.458 Disconnected: Unable to authenticate
</code>```

答: The problem was that the password had $ in it.  Once they were escaped as @MartinPrikry recommended it solved the problem and everything works now.</p>

Body:
I am trying to automate the transfer of a file via SFTP using PowerShell.  The SFTP connection requires public/private key and username/password.  I am using WinSCP to do the transfer in PowerShell.  After the authentication via the keys it fails right afterwards.  It seems to have to do with Interactive mode being required.  If I was using FileZilla to manually do this I have to do it in Interactive mode and type the password in after the keys are exchanged to get connected.

Add-Type -Path "WinSCPnet.dll"

$sessionOptions = New-Object WinSCP.SessionOptions -Property @{
    Protocol = [WinSCP.Protocol]::Sftp
    HostName = "stage.sample.com"
    PortNumber= 22
    UserName = "MyUsername"
    Password = "MyPassword"
    SshHostKeyFingerprint = "ssh-rsa 1024 znVXTS2xndXS4dKADWyRUUzImR/kG1Ipojlr2eL2765="
    SshPrivateKeyPath="D:\PrivateKeys\private.ppk"
    PrivateKeyPassphrase="MyPrivateKeypassword"
}

$session = New-Object WinSCP.Session

try
{
    # Connect
    $session.Open($sessionOptions)
    # Your code
    $session.PutFiles("d:\6201_2019-04-15.zip", "\6201_2019-04-15.zip")
}
finally
{
    $session.Dispose()
}

WinSCP Log when using the UI and it works:

. 2019-05-28 09:35:25.692 --------------------------------------------------------------------------
. 2019-05-28 09:35:25.692 WinSCP Version 5.15.1 (Build 9407) (OS 6.1.7601 Service Pack 1 - Windows Server 2008 R2 Standard)
. 2019-05-28 09:35:25.692 Configuration: D:\Ei Dynamics\sftp\WinSCP.ini
. 2019-05-28 09:35:25.693 Log level: Normal
. 2019-05-28 09:35:25.693 Local account: B\a_xyz
. 2019-05-28 09:35:25.693 Working directory: D:\Ei Dynamics\sftp
. 2019-05-28 09:35:25.693 Process ID: 11292
. 2019-05-28 09:35:25.693 Command-line: "D:\Ei Dynamics\sftp\WinSCP.exe"
. 2019-05-28 09:35:25.694 Time zone: Current: GMT-5, Standard: GMT-6 (Central Standard Time), DST: GMT-5 (Central Daylight Time), DST Start: 3/10/2019, DST End: 11/3/2019
. 2019-05-28 09:35:25.694 Login time: Tuesday, May 28, 2019 9:35:25 AM
. 2019-05-28 09:35:25.694 --------------------------------------------------------------------------
. 2019-05-28 09:35:25.694 Session name: MyUsername@stage.example.com (Modified site)
. 2019-05-28 09:35:25.694 Host name: stage.example.com (Port: 10022)
. 2019-05-28 09:35:25.694 User name: MyUsername (Password: Yes, Key file: Yes, Passphrase: No)
. 2019-05-28 09:35:25.694 Tunnel: No
. 2019-05-28 09:35:25.694 Transfer Protocol: SFTP (SCP)
. 2019-05-28 09:35:25.694 Ping type: Off, Ping interval: 30 sec; Timeout: 15 sec
. 2019-05-28 09:35:25.694 Disable Nagle: No
. 2019-05-28 09:35:25.694 Proxy: None
. 2019-05-28 09:35:25.694 Send buffer: 262144
. 2019-05-28 09:35:25.694 SSH protocol version: 2; Compression: No
. 2019-05-28 09:35:25.694 Bypass authentication: No
. 2019-05-28 09:35:25.694 Try agent: Yes; Agent forwarding: No; TIS/CryptoCard: No; KI: Yes; GSSAPI: Yes
. 2019-05-28 09:35:25.694 GSSAPI: Forwarding: No; Libs: gssapi32,sspi,custom; Custom:
. 2019-05-28 09:35:25.694 Ciphers: aes,chacha20,blowfish,3des,WARN,arcfour,des; Ssh2DES: No
. 2019-05-28 09:35:25.694 KEX: ecdh,dh-gex-sha1,dh-group14-sha1,rsa,WARN,dh-group1-sha1
. 2019-05-28 09:35:25.694 SSH Bugs: Auto,Auto,Auto,Auto,Auto,Auto,Auto,Auto,Auto,Auto,Auto,Auto,Auto
. 2019-05-28 09:35:25.694 Simple channel: Yes
. 2019-05-28 09:35:25.694 Return code variable: Autodetect; Lookup user groups: Auto
. 2019-05-28 09:35:25.694 Shell: default
. 2019-05-28 09:35:25.694 EOL: LF, UTF: Auto
. 2019-05-28 09:35:25.694 Clear aliases: Yes, Unset nat.vars: Yes, Resolve symlinks: Yes; Follow directory symlinks: No
. 2019-05-28 09:35:25.694 LS: ls -la, Ign LS warn: Yes, Scp1 Comp: No; Exit code 1 is error: No
. 2019-05-28 09:35:25.694 SFTP Bugs: Auto,Auto
. 2019-05-28 09:35:25.694 SFTP Server: default
. 2019-05-28 09:35:25.694 Local directory: default, Remote directory: home, Update: Yes, Cache: Yes
. 2019-05-28 09:35:25.694 Cache directory changes: Yes, Permanent: Yes
. 2019-05-28 09:35:25.694 Recycle bin: Delete to: No, Overwritten to: No, Bin path:
. 2019-05-28 09:35:25.694 DST mode: Unix
. 2019-05-28 09:35:25.694 --------------------------------------------------------------------------
. 2019-05-28 09:35:25.723 Looking up host "stage.example.com" for SSH connection
. 2019-05-28 09:35:25.724 Connecting to 192.123.100.123 port 10022
. 2019-05-28 09:35:25.747 We claim version: SSH-2.0-WinSCP_release_5.15.1
. 2019-05-28 09:35:25.778 Server version: SSH-2.0-Maverick_SSHD
. 2019-05-28 09:35:25.778 Using SSH protocol version 2
. 2019-05-28 09:35:25.783 Have a known host key of type rsa2
. 2019-05-28 09:35:25.785 Doing Diffie-Hellman group exchange
. 2019-05-28 09:35:25.875 Doing Diffie-Hellman key exchange with hash SHA-1
. 2019-05-28 09:35:26.106 Host key fingerprint is:
. 2019-05-28 09:35:26.106 ssh-rsa 1024 e6:c8:78:79:f9:d4:e9:af:f2:53:28:6d:87:c8:62:f5 znVXTS2xndXS4dKADWyRUUzImR/kG1Ipojlr2eL1234=
. 2019-05-28 09:35:26.111 Host key matches cached key
. 2019-05-28 09:35:26.113 Initialised AES-256 CBC client->server encryption
. 2019-05-28 09:35:26.113 Initialised HMAC-SHA1 client->server MAC algorithm
. 2019-05-28 09:35:26.113 Initialised AES-256 CBC server->client encryption
. 2019-05-28 09:35:26.113 Initialised HMAC-SHA1 server->client MAC algorithm
. 2019-05-28 09:35:26.196 Reading key file "D:\privateKeys\myprivate.ppk"
! 2019-05-28 09:35:26.196 Using username "MyUsername".
. 2019-05-28 09:35:31.197 Server offered these authentication methods: password,publickey,keyboard-interactive
. 2019-05-28 09:35:31.197 Offered public key
. 2019-05-28 09:35:31.247 Offer of public key accepted
! 2019-05-28 09:35:31.247 Authenticating with public key "rsa-key-20190313"
. 2019-05-28 09:35:31.262 Prompt (passphrase, "SSH key passphrase", <no instructions>, "Passphrase for key "rsa-key-20190313": ")
. 2019-05-28 09:35:33.837 Sent public key signature
! 2019-05-28 09:35:33.864 Further authentication required
. 2019-05-28 09:35:33.869 Further authentication required
. 2019-05-28 09:35:33.869 Server offered these authentication methods: password,keyboard-interactive8ƒÆqtY"Ç4¡FØwFÎ±[D*ó6çeÊNô§1‚>°
. 2019-05-28 09:35:33.869 Attempting keyboard-interactive authentication
. 2019-05-28 09:35:33.895 Prompt (keyboard interactive, "SSH server: password", "Using keyboard-interactive authentication.
. 2019-05-28 09:35:33.895 Enter Password for MyUsername:", "Password:")
. 2019-05-28 09:35:33.895 Using stored password.
. 2019-05-28 09:35:33.958 Access granted
. 2019-05-28 09:35:33.958 Opening session as main channel
. 2019-05-28 09:35:33.982 Opened main channel
. 2019-05-28 09:35:34.149 Started a shell/command
. 2019-05-28 09:35:34.157 --------------------------------------------------------------------------
. 2019-05-28 09:35:34.158 Using SFTP protocol.
. 2019-05-28 09:35:34.160 Doing startup conversation with host.
> 2019-05-28 09:35:34.170 Type: SSH_FXP_INIT, Size: 5, Number: -1
< 2019-05-28 09:35:34.193 Type: SSH_FXP_VERSION, Size: 33, Number: -1
. 2019-05-28 09:35:34.193 SFTP version 3 negotiated.
. 2019-05-28 09:35:34.193 Unknown server extension newline@vandyke.com="\n"
. 2019-05-28 09:35:34.193 We believe the server has signed timestamps bug
. 2019-05-28 09:35:34.193 We will use UTF-8 strings until server sends an invalid UTF-8 string as with SFTP version 3 and older UTF-8 strings are not mandatory
. 2019-05-28 09:35:34.193 Getting current directory name.
. 2019-05-28 09:35:34.193 Getting real path for '.'
> 2019-05-28 09:35:34.193 Type: SSH_FXP_REALPATH, Size: 10, Number: 2832
< 2019-05-28 09:35:34.226 Type: SSH_FXP_NAME, Size: 51, Number: 2832
. 2019-05-28 09:35:34.226 Real path is '/'
. 2019-05-28 09:35:34.267 Listing directory "/".
> 2019-05-28 09:35:34.267 Type: SSH_FXP_OPENDIR, Size: 10, Number: 3083
< 2019-05-28 09:35:34.296 Type: SSH_FXP_HANDLE, Size: 10, Number: 3083
> 2019-05-28 09:35:34.296 Type: SSH_FXP_READDIR, Size: 10, Number: 3340
< 2019-05-28 09:35:34.394 Type: SSH_FXP_NAME, Size: 112, Number: 3340
> 2019-05-28 09:35:34.394 Type: SSH_FXP_READDIR, Size: 10, Number: 3596
< 2019-05-28 09:35:34.426 Type: SSH_FXP_STATUS, Size: 45, Number: 3596
< 2019-05-28 09:35:34.426 Status code: 1
> 2019-05-28 09:35:34.426 Type: SSH_FXP_CLOSE, Size: 10, Number: 3844
. 2019-05-28 09:35:34.426 3098;d;0;2019-05-28T14:35:34.000Z;3;"300" [300];"100" [100];rwx------;0
. 2019-05-28 09:35:34.426 ..;D;0;1899-12-30T06:00:00.000Z;0;"" [0];"" [0];---------;0
. 2019-05-28 09:35:34.482 Startup conversation with host finished.
. 2019-05-28 09:35:50.983 Received disconnect message (by application)
. 2019-05-28 09:35:50.983 Disconnection message text: Idle connection
. 2019-05-28 09:35:50.983 Server sent disconnect message
. 2019-05-28 09:35:50.983 type 11 (by application):
. 2019-05-28 09:35:50.983 "Idle connection"
. 2019-05-28 09:38:36.501 Received disconnect message (by application)
. 2019-05-28 09:38:36.501 Disconnection message text: Idle connection
. 2019-05-28 09:38:36.501 Server sent disconnect message
. 2019-05-28 09:38:36.501 type 11 (by application):
. 2019-05-28 09:38:36.501 "Idle connection"
* 2019-05-28 09:38:36.501 (ESshFatal) Server sent disconnect message
* 2019-05-28 09:38:36.501 type 11 (by application):
* 2019-05-28 09:38:36.501 "Idle connection"
. 2019-05-28 09:38:45.572 Looking up host "stage.example.com" for SSH connection
. 2019-05-28 09:38:45.573 Connecting to 192.123.100.123 port 10022
. 2019-05-28 09:38:45.595 We claim version: SSH-2.0-WinSCP_release_5.15.1
. 2019-05-28 09:38:45.619 Server version: SSH-2.0-Maverick_SSHD
. 2019-05-28 09:38:45.619 Using SSH protocol version 2
. 2019-05-28 09:38:45.621 Have a known host key of type rsa2
. 2019-05-28 09:38:45.622 Doing Diffie-Hellman group exchange
. 2019-05-28 09:38:45.717 Doing Diffie-Hellman key exchange with hash SHA-1
. 2019-05-28 09:38:45.865 Host key fingerprint is:
. 2019-05-28 09:38:45.865 ssh-rsa 1024 e6:c8:78:79:f9:d4:e9:af:f2:53:28:6d:87:c8:62:f5 znVXTS2xndXS4dKADWyRUUzImR/kG1Ipojlr2e1234=
. 2019-05-28 09:38:45.910 Host key matches cached key
. 2019-05-28 09:38:45.911 Initialised AES-256 CBC client->server encryption
. 2019-05-28 09:38:45.911 Initialised HMAC-SHA1 client->server MAC algorithm
. 2019-05-28 09:38:45.911 Initialised AES-256 CBC server->client encryption
. 2019-05-28 09:38:45.911 Initialised HMAC-SHA1 server->client MAC algorithm
. 2019-05-28 09:38:45.996 Reading key file "D:\privateKeys\myprivate.ppk"
! 2019-05-28 09:38:45.996 Using username "MyUsername".
. 2019-05-28 09:39:19.037 Received disconnect message (by application)
. 2019-05-28 09:39:19.037 Disconnection message text: Idle connection
. 2019-05-28 09:39:19.037 Server sent disconnect message
. 2019-05-28 09:39:19.037 type 11 (by application):
. 2019-05-28 09:39:19.037 "Idle connection"

Powershell Log file

. 2019-05-28 09:37:41.686 --------------------------------------------------------------------------
. 2019-05-28 09:37:41.686 WinSCP Version 5.15.1 (Build 9407) (OS 6.1.7601 Service Pack 1 - Windows Server 2008 R2 Standard)
. 2019-05-28 09:37:41.686 Configuration: nul
. 2019-05-28 09:37:41.686 Log level: Normal
. 2019-05-28 09:37:41.686 Local account: B\a_xyz
. 2019-05-28 09:37:41.686 Working directory: D:\Ei Dynamics\sftp
. 2019-05-28 09:37:41.686 Process ID: 132
. 2019-05-28 09:37:41.687 Command-line: "D:\Ei Dynamics\sftp\winscp.exe" /xmllog="C:\Users\a_xyz\AppData\Local\Temp\13\wscp2EA0.01871C8A.tmp" /xmlgroups /xmllogrequired /nointeractiveinput /dotnet=5.15.1  /ini=nul /log="D:\Ei Dynamics\sftp\powershell.log"  /console /consoleinstance=_11936_48002702_723
. 2019-05-28 09:37:41.687 Time zone: Current: GMT-5, Standard: GMT-6 (Central Standard Time), DST: GMT-5 (Central Daylight Time), DST Start: 3/10/2019, DST End: 11/3/2019
. 2019-05-28 09:37:41.687 Login time: Tuesday, May 28, 2019 9:37:41 AM
. 2019-05-28 09:37:41.687 --------------------------------------------------------------------------
. 2019-05-28 09:37:41.687 Script: Retrospectively logging previous script records:
> 2019-05-28 09:37:41.687 Script: option batch on
< 2019-05-28 09:37:41.687 Script: batch           on
< 2019-05-28 09:37:41.687 Script: reconnecttime   120
> 2019-05-28 09:37:41.687 Script: option confirm off
< 2019-05-28 09:37:41.687 Script: confirm         off
> 2019-05-28 09:37:41.687 Script: option reconnecttime 120
< 2019-05-28 09:37:41.687 Script: reconnecttime   120
> 2019-05-28 09:37:41.687 Script: open sftp://MyUsername:***@stage.example.com:10022 -hostkey="ssh-rsa 1024 znVXTS2xndXS4dKADWyRUUzImR/kG1Ipojlr2eL1234=" -privatekey="D:\PrivateKeys\myprivate.ppk" -timeout=15 -passphrase=***
. 2019-05-28 09:37:41.687 --------------------------------------------------------------------------
. 2019-05-28 09:37:41.687 Session name: MyUsername@stage.example.com (Ad-Hoc site)
. 2019-05-28 09:37:41.687 Host name: stage.example.com (Port: 10022)
. 2019-05-28 09:37:41.688 User name: MyUsername (Password: Yes, Key file: Yes, Passphrase: Yes)
. 2019-05-28 09:37:41.688 Tunnel: No
. 2019-05-28 09:37:41.688 Transfer Protocol: SFTP
. 2019-05-28 09:37:41.688 Ping type: Off, Ping interval: 30 sec; Timeout: 15 sec
. 2019-05-28 09:37:41.688 Disable Nagle: No
. 2019-05-28 09:37:41.688 Proxy: None
. 2019-05-28 09:37:41.688 Send buffer: 262144
. 2019-05-28 09:37:41.688 SSH protocol version: 2; Compression: No
. 2019-05-28 09:37:41.688 Bypass authentication: No
. 2019-05-28 09:37:41.688 Try agent: Yes; Agent forwarding: No; TIS/CryptoCard: No; KI: Yes; GSSAPI: Yes
. 2019-05-28 09:37:41.688 GSSAPI: Forwarding: No; Libs: gssapi32,sspi,custom; Custom:
. 2019-05-28 09:37:41.688 Ciphers: aes,chacha20,blowfish,3des,WARN,arcfour,des; Ssh2DES: No
. 2019-05-28 09:37:41.688 KEX: ecdh,dh-gex-sha1,dh-group14-sha1,rsa,WARN,dh-group1-sha1
. 2019-05-28 09:37:41.688 SSH Bugs: Auto,Auto,Auto,Auto,Auto,Auto,Auto,Auto,Auto,Auto,Auto,Auto,Auto
. 2019-05-28 09:37:41.688 Simple channel: Yes
. 2019-05-28 09:37:41.688 Return code variable: Autodetect; Lookup user groups: Auto
. 2019-05-28 09:37:41.688 Shell: default
. 2019-05-28 09:37:41.688 EOL: LF, UTF: Auto
. 2019-05-28 09:37:41.688 Clear aliases: Yes, Unset nat.vars: Yes, Resolve symlinks: Yes; Follow directory symlinks: No
. 2019-05-28 09:37:41.688 LS: ls -la, Ign LS warn: Yes, Scp1 Comp: No; Exit code 1 is error: No
. 2019-05-28 09:37:41.688 SFTP Bugs: Auto,Auto
. 2019-05-28 09:37:41.688 SFTP Server: default
. 2019-05-28 09:37:41.688 Local directory: default, Remote directory: home, Update: Yes, Cache: Yes
. 2019-05-28 09:37:41.688 Cache directory changes: Yes, Permanent: Yes
. 2019-05-28 09:37:41.688 Recycle bin: Delete to: No, Overwritten to: No, Bin path:
. 2019-05-28 09:37:41.688 DST mode: Unix
. 2019-05-28 09:37:41.688 --------------------------------------------------------------------------
. 2019-05-28 09:37:41.689 Looking up host "stage.example.com" for SSH connection
. 2019-05-28 09:37:41.736 Connecting to 192.123.100.123 port 10022
. 2019-05-28 09:37:41.757 We claim version: SSH-2.0-WinSCP_release_5.15.1
. 2019-05-28 09:37:41.782 Server version: SSH-2.0-Maverick_SSHD
. 2019-05-28 09:37:41.782 Using SSH protocol version 2
. 2019-05-28 09:37:41.782 Have a known host key of type rsa2
. 2019-05-28 09:37:41.782 Doing Diffie-Hellman group exchange
. 2019-05-28 09:37:41.872 Doing Diffie-Hellman key exchange with hash SHA-1
. 2019-05-28 09:37:42.039 Host key fingerprint is:
. 2019-05-28 09:37:42.039 ssh-rsa 1024 e6:c8:78:79:f9:d4:e9:af:f2:53:28:6d:87:c8:62:f5 znVXTS2xndXS4dKADWyRUUzImR/kG1Ipojlr2eL1234=
. 2019-05-28 09:37:42.040 Host key matches configured key
. 2019-05-28 09:37:42.040 Initialised AES-256 CBC client->server encryption
. 2019-05-28 09:37:42.040 Initialised HMAC-SHA1 client->server MAC algorithm
. 2019-05-28 09:37:42.040 Initialised AES-256 CBC server->client encryption
. 2019-05-28 09:37:42.040 Initialised HMAC-SHA1 server->client MAC algorithm
. 2019-05-28 09:37:42.125 Reading key file "D:\PrivateKeys\myprivate.ppk"
! 2019-05-28 09:37:42.126 Using username "MyUsername".
. 2019-05-28 09:37:42.149 Server offered these authentication methods: password,publickey,keyboard-interactive
. 2019-05-28 09:37:42.149 Offered public key
. 2019-05-28 09:37:42.201 Offer of public key accepted
! 2019-05-28 09:37:42.201 Authenticating with public key "rsa-key-20190313"
. 2019-05-28 09:37:42.202 Prompt (passphrase, "SSH key passphrase", <no instructions>, "Passphrase for key "rsa-key-20190313": ")
. 2019-05-28 09:37:42.202 Using configured passphrase.
. 2019-05-28 09:37:42.330 Sent public key signature
! 2019-05-28 09:37:42.354 Further authentication required
. 2019-05-28 09:37:42.355 Further authentication required
. 2019-05-28 09:37:42.355 Server offered these authentication methods: password,keyboard-interactive}®”Çÿ®UÆ'Éî€ûw‘BÊMNŽoKÓU/W
. 2019-05-28 09:37:42.355 Attempting keyboard-interactive authentication
. 2019-05-28 09:37:42.377 Prompt (keyboard interactive, "SSH server: password", "Using keyboard-interactive authentication.
. 2019-05-28 09:37:42.377 Enter Password for MyUsername:", "Password:")
. 2019-05-28 09:37:42.377 Using stored password.
. 2019-05-28 09:37:42.432 Keyboard-interactive authentication failed
! 2019-05-28 09:37:42.432 Access denied
. 2019-05-28 09:37:42.436 Server offered these authentication methods: password,keyboard-interactive
. 2019-05-28 09:37:42.436 Attempting keyboard-interactive authentication
. 2019-05-28 09:37:42.458 Prompt (keyboard interactive, "SSH server: password", "Using keyboard-interactive authentication.
. 2019-05-28 09:37:42.458 Invalid Password, reenter Password for MyUsername:", "Password:")
. 2019-05-28 09:37:42.458 Disconnected: Unable to authenticate


问:
Create a vector of inclusive numbers in a dataframe in R
Reproducible data:

```<code>Start_Curr_Job <- c(2009, 2011, 2014)
End_Curr_Job <- c(2012, 2015, 2019)
data_clean <- data.frame(Start_Curr_Job, End_Curr_Job)
</code>```

I have a data frame with columns "startyear" and "endyear". I am trying to create a 3rd column that will contain an inclusive list of all the years in between, but my code below is not working out.

For example, for startyear = 2009 and endyear = 2012, allyears should equal 2009, 2010, 2011, 2012.

Any suggestions will be appreciated. My code below:

```<code>data_clean <- data_raw %>%
  filter(!is.na(Start_Curr_Job), !is.na(End_Curr_Job),
         Start_Curr_Job != "NA", End_Curr_Job != "NA" ) %>%
  mutate(Start_Curr_Job = as.numeric(Start_Curr_Job),
         End_Curr_Job = as.numeric(End_Curr_Job)) %>%
mutate(all_years = seq(from = Start_Curr_Job, to = End_Curr_Job, by = 1))
</code>```

Error Message: "Error in seq.default(from = Start_Curr_Job, to = End_Curr_Job, by = 1) :
  'from' must be of length 1"

I also tried the following, but it produced allyears = "2019:2012", which is also not what I want.

```<code>  for (row in 1:nrow(data_clean)) {
    data_clean$years[row] <- list(data_clean$Start_Curr_Job[row]:data_clean$End_Curr_Job[row])
  }
</code>```

答:
The issue here is the seq is not vectorised so it cannot accept a vector as its arguments. There is another post that outlines how to vectorise the function here.

Otherwise another approach is to use the map2_ functions from the purrr package. Reprex below

library(tidyverse)
library(purrr)

Start_Curr_Job <- c(2009, 2011, 2014)
End_Curr_Job <- c(2012, 2015, 2019)
data_raw <- data.frame(Start_Curr_Job, End_Curr_Job)

data_clean <- data_raw %>%
  filter(!is.na(Start_Curr_Job), !is.na(End_Curr_Job),
         Start_Curr_Job != "NA", End_Curr_Job != "NA" ) %>%
  mutate(Start_Curr_Job = as.numeric(Start_Curr_Job),
         End_Curr_Job = as.numeric(End_Curr_Job)) %>%
  mutate(all_years =  purrr::map2_chr(.x = Start_Curr_Job, .y = End_Curr_Job, .f = ~paste(seq(.x, .y), collapse = ", ")))

data_clean
#>   Start_Curr_Job End_Curr_Job                          all_years
#> 1           2009         2012             2009, 2010, 2011, 2012
#> 2           2011         2015       2011, 2012, 2013, 2014, 2015
#> 3           2014         2019 2014, 2015, 2016, 2017, 2018, 2019
```

Created on 2019-05-29 by the reprex package (v0.2.1)

Body:
Reproducible data:

Start_Curr_Job <- c(2009, 2011, 2014)
End_Curr_Job <- c(2012, 2015, 2019)
data_clean <- data.frame(Start_Curr_Job, End_Curr_Job)

I have a data frame with columns "startyear" and "endyear". I am trying to create a 3rd column that will contain an inclusive list of all the years in between, but my code below is not working out.

For example, for startyear = 2009 and endyear = 2012, allyears should equal 2009, 2010, 2011, 2012.

Any suggestions will be appreciated. My code below:

data_clean <- data_raw %>%
  filter(!is.na(Start_Curr_Job), !is.na(End_Curr_Job),
         Start_Curr_Job != "NA", End_Curr_Job != "NA" ) %>%
  mutate(Start_Curr_Job = as.numeric(Start_Curr_Job),
         End_Curr_Job = as.numeric(End_Curr_Job)) %>%
mutate(all_years = seq(from = Start_Curr_Job, to = End_Curr_Job, by = 1))

Error Message: "Error in seq.default(from = Start_Curr_Job, to = End_Curr_Job, by = 1) :
  'from' must be of length 1"

I also tried the following, but it produced allyears = "2019:2012", which is also not what I want.

  for (row in 1:nrow(data_clean)) {
    data_clean$years[row] <- list(data_clean$Start_Curr_Job[row]:data_clean$End_Curr_Job[row])
  }

Body:
The issue here is the seq is not vectorised so it cannot accept a vector as its arguments. There is another post that outlines how to vectorise the function here.

Otherwise another approach is to use the map2_ functions from the purrr package. Reprex below

library(tidyverse)
library(purrr)

Start_Curr_Job <- c(2009, 2011, 2014)
End_Curr_Job <- c(2012, 2015, 2019)
data_raw <- data.frame(Start_Curr_Job, End_Curr_Job)

data_clean <- data_raw %>%
  filter(!is.na(Start_Curr_Job), !is.na(End_Curr_Job),
         Start_Curr_Job != "NA", End_Curr_Job != "NA" ) %>%
  mutate(Start_Curr_Job = as.numeric(Start_Curr_Job),
         End_Curr_Job = as.numeric(End_Curr_Job)) %>%
  mutate(all_years =  purrr::map2_chr(.x = Start_Curr_Job, .y = End_Curr_Job, .f = ~paste(seq(.x, .y), collapse = ", ")))

data_clean
#>   Start_Curr_Job End_Curr_Job                          all_years
#> 1           2009         2012             2009, 2010, 2011, 2012
#> 2           2011         2015       2011, 2012, 2013, 2014, 2015
#> 3           2014         2019 2014, 2015, 2016, 2017, 2018, 2019

Created on 2019-05-29 by the reprex package (v0.2.1)


问:
How to move an image with HTML and JS
I'm trying to move an image within a set radius of 100 pixels. I'm having some trouble getting it to work.

I'm using setInterval to make it repeatedly move and random to set where it moves.

Full JS code:

```<code>function start () {
  const imgH = 111;
  const imgW = 112;
  const scrnH = screen.availHeight;
  const scrnW = screen.availWidth;
  var objX = scrnW/2 - imgW/2;
  var objY = scrnH/2 - imgH/2;
  document.getElementById("monka").style.top = objY + "px";
  document.getElementById("monka").style.left = objX + "px";
  var x = document.getElementById("monka").style.left;
  var y = document.getElementById("monka").style.top;
  var deltaX = 0;
  var deltaY = 0;
  function move () {
    if ((Math.sqrt(x ** 2 + y ** 2) >= 100) || (deltaX == 0 && deltaY == 0)) {
      deltaX = -1 * deltaX;
      deltaY = -1 * deltaY;
    } else {
      x += deltaX;
      y += deltaY;
      document.getElementById("monka").style.left = x;
      document.getElementById("monka").style.top = y;
      deltaX = Math.ceil(Math.random() * 50) - 25;
      deltaY = Math.ceil(Math.random() * 50) - 25;
    }
  }
  setInterval("move()", 100);
}
</code>```

Full HTML code:

```<code><!DOCTYPE html>
<html>
  <head>
    <title>Random Movement</title>
    <link href="style.css" rel="stylesheet" type="text/css" />
    <script src="script.js"></script>
  </head>
  <body onLoad="start();">
    <img src="monkaW.png" id="monka" style="">
  </body>
</html>
</code>```

答:
Try this on for size. I found several things with your code that I would have done differently, so I heavily commented the answer.

//I moved some of your declarations outside the function to make them global. I don't think the way you set up your move function inside your start function is a good practice. Keep things separated and modular as much as possible
var monka = document.getElementById("monka");
var deltaX = 0;
var deltaY = 0;
//I changed x and y to be centerX and centerY, which is a more descriptive name for them, as they will be the starting x and y values for the picture
var objX, objY, centerX, centerY;

function start () {
  //I'm using document.body.clientHeight and Width instead of screen.AvailHeight and Width because those values don't work if you have an iframe or a window of less than maximum screen size
  const scrnH = document.body.clientHeight;
  const scrnW = document.body.clientWidth;
  const imgH = 111;
  const imgW = 112;
  objX = scrnW/2 - imgW/2;
  objY = scrnH/2 - imgH/2;
  monka.style.top = objY + "px";
  monka.style.left = objX + "px";
  //At the beginning I need to explicitly set these variables to the same value so I can do math with thme later
  centerX = objX;
  centerY = objY;
}

function move () {
  //I moved around the order of things in this function so it would work. The first thing you need to do is figure out your random number between -25 and 25
  deltaX = Math.ceil(Math.random() * 50) - 25;
  deltaY = Math.ceil(Math.random() * 50) - 25;
  //The logic here can probably be improved a little, I feel like someone smarter can trim this down a little. Basically I get my new coordinates, then figure out if the picture is more than 100px away from where it started, if it is then I subtract twice as much as I just added. Liek I said, this could be improved but it works
  objX += deltaX;
  objY += deltaY;
 if ((Math.sqrt((centerX - objX) ** 2 + (centerY - objY) ** 2) >= 100)) {
   deltaX = -2 * deltaX;
    deltaY = -2 * deltaY;
    objX += deltaX;
   objY += deltaY;
    //Need to add logic here to prevent your top and left values from becoming negative
  }
  //This needs to be converted from a number to a pixel value
  monka.style.left = objX + "px";
  monka.style.top = objY + "px";
}

window.onload = start();
//I changed this to 500ms because 100ms was making my eyes go crazy
setInterval(move, 500);```
<pre class="snippet-code-css lang-css prettyprint-override"><code>/* I put this rule in to make sure the body covers the entire viewable portion of your browser */
body, html {
  height: 100%
}
/* you need to give the picture an absolute position or else you cannot place it using top and left attributes */
#monka {
  position: absolute
}</code>```

```

Title: How to move an image with HTML and JS

Body:
I'm trying to move an image within a set radius of 100 pixels. I'm having some trouble getting it to work.

I'm using setInterval to make it repeatedly move and random to set where it moves.

Full JS code:

function start () {
  const imgH = 111;
  const imgW = 112;
  const scrnH = screen.availHeight;
  const scrnW = screen.availWidth;
  var objX = scrnW/2 - imgW/2;
  var objY = scrnH/2 - imgH/2;
  document.getElementById("monka").style.top = objY + "px";
  document.getElementById("monka").style.left = objX + "px";
  var x = document.getElementById("monka").style.left;
  var y = document.getElementById("monka").style.top;
  var deltaX = 0;
  var deltaY = 0;
  function move () {
    if ((Math.sqrt(x ** 2 + y ** 2) >= 100) || (deltaX == 0 && deltaY == 0)) {
      deltaX = -1 * deltaX;
      deltaY = -1 * deltaY;
    } else {
      x += deltaX;
      y += deltaY;
      document.getElementById("monka").style.left = x;
      document.getElementById("monka").style.top = y;
      deltaX = Math.ceil(Math.random() * 50) - 25;
      deltaY = Math.ceil(Math.random() * 50) - 25;
    }
  }
  setInterval("move()", 100);
}

Full HTML code:

<!DOCTYPE html>

    <title>Random Movement</title>
    <link href="style.css" rel="stylesheet" type="text/css" />

Body:
Try this on for size. I found several things with your code that I would have done differently, so I heavily commented the answer.

//I moved some of your declarations outside the function to make them global. I don't think the way you set up your move function inside your start function is a good practice. Keep things separated and modular as much as possible
var monka = document.getElementById("monka");
var deltaX = 0;
var deltaY = 0;
//I changed x and y to be centerX and centerY, which is a more descriptive name for them, as they will be the starting x and y values for the picture
var objX, objY, centerX, centerY;

function start () {
  //I'm using document.body.clientHeight and Width instead of screen.AvailHeight and Width because those values don't work if you have an iframe or a window of less than maximum screen size
  const scrnH = document.body.clientHeight;
  const scrnW = document.body.clientWidth;
  const imgH = 111;
  const imgW = 112;
  objX = scrnW/2 - imgW/2;
  objY = scrnH/2 - imgH/2;
  monka.style.top = objY + "px";
  monka.style.left = objX + "px";
  //At the beginning I need to explicitly set these variables to the same value so I can do math with thme later
  centerX = objX;
  centerY = objY;
}

function move () {
  //I moved around the order of things in this function so it would work. The first thing you need to do is figure out your random number between -25 and 25
  deltaX = Math.ceil(Math.random() * 50) - 25;
  deltaY = Math.ceil(Math.random() * 50) - 25;
  //The logic here can probably be improved a little, I feel like someone smarter can trim this down a little. Basically I get my new coordinates, then figure out if the picture is more than 100px away from where it started, if it is then I subtract twice as much as I just added. Liek I said, this could be improved but it works
  objX += deltaX;
  objY += deltaY;
 if ((Math.sqrt((centerX - objX) ** 2 + (centerY - objY) ** 2) >= 100)) {
   deltaX = -2 * deltaX;
    deltaY = -2 * deltaY;
    objX += deltaX;
   objY += deltaY;
    //Need to add logic here to prevent your top and left values from becoming negative
  }
  //This needs to be converted from a number to a pixel value
  monka.style.left = objX + "px";
  monka.style.top = objY + "px";
}

window.onload = start();
//I changed this to 500ms because 100ms was making my eyes go crazy
setInterval(move, 500);

/* I put this rule in to make sure the body covers the entire viewable portion of your browser */
body, html {
  height: 100%
}
/* you need to give the picture an absolute position or else you cannot place it using top and left attributes */
#monka {
  position: absolute
}

<img src="https://placekitten.com/111/112" id="monka">


问:
What is a working method for extracting numeric values with associated data from open text?
I tried to look for a solution but nothing was giving me quite what I needed. I'm not sure regex can do what I need.

I need to process a large amount of data where license information is provided. I just need to grab the number of licenses and the name for each license then group and tally the license counts for each company.

Here's an example of the data pulled:

```<code>L00129A578-E105C1D138   1 Centralized Recording

$42.00
L00129A677-213DC6D60E   1 Centralized Recording

$42.00
1005272AE2-C1D6CACEC8   5 Station

$45.00
100525B658-3AC4D2C93A   5 Station

$45.00
</code>```

I would need to grab the license count and license name then add like objects so it would grab (1 Centralized Recording, 1 Centralized Recording, 5 Station, 5 Station) then add license counts and output (2 Centralized Recording, 10 Station)

What would be the easiest way to implement this?

答:
It looks like you're trying to ignore the license number, and get the count and name. So, the following should point you on your way for your data, if it is as uniform as it seems:

import re
r = re.compile(r"\s+(\d+)\s+[A-Za-z ]+")
r = re.compile(r"\s+(\d+)\s+([A-Za-z ]+)")
m = r.search(" 1   Centralized")
m.groups()
# ('1', 'Centralized')
```

<p>That regex just says, "Require but ignore 1 or more spaces, pay attention to the string of digits after it, require but ignore 1 or more spaces after it, and pay attention to the capital letters, lower case letters, and spaces after it." (You may need to trim of a newline when you're done.)</p>

<p>The file-handling bit would look like:</p>

<pre class="lang-py prettyprint-override"><code>f = open('/path/to/your_data_file.txt')
for line in f.readlines():
    # run regex and do stuff for each line
    pass
</code>```

Body:
I tried to look for a solution but nothing was giving me quite what I needed. I'm not sure regex can do what I need.

I need to process a large amount of data where license information is provided. I just need to grab the number of licenses and the name for each license then group and tally the license counts for each company.

Here's an example of the data pulled:

L00129A578-E105C1D138   1 Centralized Recording

$42.00
L00129A677-213DC6D60E   1 Centralized Recording

$42.00
1005272AE2-C1D6CACEC8   5 Station

$45.00
100525B658-3AC4D2C93A   5 Station

$45.00

I would need to grab the license count and license name then add like objects so it would grab (1 Centralized Recording, 1 Centralized Recording, 5 Station, 5 Station) then add license counts and output (2 Centralized Recording, 10 Station)

What would be the easiest way to implement this?

Body:
It looks like you're trying to ignore the license number, and get the count and name. So, the following should point you on your way for your data, if it is as uniform as it seems:

import re
r = re.compile(r"\s+(\d+)\s+[A-Za-z ]+")
r = re.compile(r"\s+(\d+)\s+([A-Za-z ]+)")
m = r.search(" 1   Centralized")
m.groups()
# ('1', 'Centralized')

That regex just says, "Require but ignore 1 or more spaces, pay attention to the string of digits after it, require but ignore 1 or more spaces after it, and pay attention to the capital letters, lower case letters, and spaces after it." (You may need to trim of a newline when you're done.)

The file-handling bit would look like:

f = open('/path/to/your_data_file.txt')
for line in f.readlines():
    # run regex and do stuff for each line
    pass


问:
reactstrap with typescript, define ambient module
I want to use reactstrap with typescript.

There are typings for these typings: https://github.com/DefinitelyTyped/DefinitelyTyped/blob/master/types/reactstrap/index.d.ts

Reactstrap is availabe on page as Reactstrap global variable. I thought adding it in ambient module would be as simple as adding react and react dom

Here's my global.d.ts

```<code>import * as react from "react"
import * as react_dom from "react-dom"
import * as reactstrap from "reactstrap"

declare global {
    type React = typeof react
    type ReactDOM = typeof react_dom
    type Reactstrap = typeof reactstrap
}
</code>```

I can use React.Component and jsx without importing, it's available globally. But i can't use Reactstrap.Alert, tsc says thatReactstrap.Alert is a type but used like a value.

I can manually add this string export as namespace Reactstrap in a d.ts file, but it looks like a hack, and this changes are not stored in my git repo. Is it possible to export all classes from one d.ts and put it into namespace of another?

答:
I've created file _reactstrap.d.ts next to global.d.ts with this content:

```<code>export * from "reactstrap"

export as namespace Reactstrap;
</code>```

And modified global.d.ts as follows:

```<code>import * as react from "react"
import * as react_dom from "react-dom"
import * as reactstrap from "./_reactstrap"

declare global {
    type React = typeof react
    type ReactDOM = typeof react_dom
    type Reactstrap = typeof reactstrap
}
</code>```

Body:
I want to use reactstrap with typescript.

There are typings for these typings: https://github.com/DefinitelyTyped/DefinitelyTyped/blob/master/types/reactstrap/index.d.ts

Reactstrap is availabe on page as Reactstrap global variable. I thought adding it in ambient module would be as simple as adding react and react dom

Here's my global.d.ts

import * as react from "react"
import * as react_dom from "react-dom"
import * as reactstrap from "reactstrap"

declare global {
    type React = typeof react
    type ReactDOM = typeof react_dom
    type Reactstrap = typeof reactstrap
}

I can use React.Component and jsx without importing, it's available globally. But i can't use Reactstrap.Alert, tsc says thatReactstrap.Alert is a type but used like a value.

I can manually add this string export as namespace Reactstrap in a d.ts file, but it looks like a hack, and this changes are not stored in my git repo. Is it possible to export all classes from one d.ts and put it into namespace of another?

Body:
I've created file _reactstrap.d.ts next to global.d.ts with this content:

export * from "reactstrap"

export as namespace Reactstrap;

And modified global.d.ts as follows:

import * as react from "react"
import * as react_dom from "react-dom"
import * as reactstrap from "./_reactstrap"

declare global {
    type React = typeof react
    type ReactDOM = typeof react_dom
    type Reactstrap = typeof reactstrap
}


问:
Python methods do not show up in user defined functions
When creating a user defined function the built-in methods do not pop up as options.

In the main body of the file the methods show up without issue. It's only when you create a function that they do not show up.

def strip_punctuation(astring):
    #punctuation_chars = ["'", '"', ",", ".", "!", ":", ";", '#', '@']
    astring.replace()
    return (astring)

```

<pre class="lang-py prettyprint-override"><code># Main file
my_string = "Word's!"
my_string.replace()
</code>```

I'd expect the same behavior in VS Code in both a user defined function as well as outside the function.

答:
If you rewrote your code with type annotations you should get what you want:

def strip_punctuation(astring: str) -> str:
    astring.replace()
    return astring
```

Body:
When creating a user defined function the built-in methods do not pop up as options.

In the main body of the file the methods show up without issue. It's only when you create a function that they do not show up.

def strip_punctuation(astring):
    #punctuation_chars = ["'", '"', ",", ".", "!", ":", ";", '#', '@']
    astring.replace()
    return (astring)

# Main file
my_string = "Word's!"
my_string.replace()

I'd expect the same behavior in VS Code in both a user defined function as well as outside the function.


问:
How do I change the font size to zoom in and out in Araxis Merge on MacOS?
I went through all the settings and the Show Fonts panel and could not find any solution.

答:
I ended up contacting support. This was their solution which I'm documenting for future searchers:

From Merge's main menu select: Araxis Merge > Preferences

Navigate to: File Comparisons > Fonts/Colours

For each of Unchanged, Inserted, Removed and Changed:
Click the Change… button, change the font size and close the font panel

Click the OK button.